|
| 23 Jan 2016 03:26 PM |
Not sure how to word that but I can explain it here.
I'm still having trouble fully understand how this instance works. A lot to do with the FilteringEnabled property in workspace but I figure it's time to learn it properly so I was hoping I could get someone to explain it for me the right way. I tried the wiki but there is terminology used in parts of the wiki that I simply don't know the definitions of and googling them pulls up results for other types of programming and every single one of those definitions also uses foreign terminology. It's just one huge loop and it's raising more questions than answers.
I want to use FilteringEnabled so that I can allow more than 1 person per server for my upcoming game, but to do that I need to learn to use RemoteEvent.
I understand enough to know that it allows client/server communication, but I never did fully understand how to use RemoteEvent properly. I know that a LocalScript can use the FireServer function but when it comes to the arguments, I'm blank.
I do know that it gets the player automatically. My understanding pretty much ends there.
What I'm trying to do right now is create an obstacle game where obstacles are randomly generated. Easy enough I suppose but I don't want players to be in the same obby. I want each obby to be localized to player clients so that each player has a unique experience. In order to do that I have no choice but to use FilteringEnabled or set the server size to 1. I'd prefer the former so that players can chat.
When the player joins, they're greeted by a gui placed into their PlayerGui... or at least I thought they would be. Apparently with FilteringEnabled on, players don't spawn with a PlayerGui. That's the first problem. I've played some games that use FilteringEnabled and they have guis on screen. Without a PlayerGui I don't understand how they can have guis on screen. So that's the first hurdle. The second issue is that after they press the PLAY button on the gui, they're characters (which are set to not auto spawn) are loaded using the Load() function which is called for by the Script in ServerScriptStorage which is called on by the RemoteEvent.
How can I solve these two problems? On top of that I also need to know if I have to use a different RemoteEvent for different functions, or if I can actually script the RemoteEvent to use different functions based on what function called the FireServer() function from other LocalScripts. |
|
|
| Report Abuse |
|
|
| |
|
Pryd7
|
  |
| Joined: 31 Aug 2012 |
| Total Posts: 577 |
|
|
| 24 Jan 2016 05:06 AM |
Wrong forum mate. Head on over to "Scriptors", you'll have more luck there
|
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 24 Jan 2016 06:06 AM |
Right forum*
"Apparently with FilteringEnabled on, players don't spawn with a PlayerGui."
Where did you hear of this? It is false info. What changes is that GUIs are actually local things and cannot be manipulated through a server script.
For the local map system you will not want to handle Character loading from the server. Since you don't want everyone to see each others' characters. You can get the character appearance with this: http://wiki.roblox.com/index.php?title=API:Class/Players/GetCharacterAppearanceAsync And recreate their character locally. Then set PlayerObject.Character to the model you made. Change the CameraObject.CameraType to Custom if it isn't already. Set the CameraObject.CameraSubject to the Humanoid object in the character.
@Last paragraph
See this example:
-- local code --
local event = remoteEventSomewhere
playButton.MouseButton1Click:connect(function() event:FireServer("play") end)
otherButton.MouseButton1Click:connect(function() event:FireServer("otherthing") end)
-- --
-- server code --
local event = remoteEventSomewhere
local actions = { ["play"] = function(Player,...) print(Player.Name .. " pressed play!") end, ["otherthing"] = function(Player,...) print(Player.Name .. " did other thing") end, }
event.OnServerEvent:connect(function(Player,action,...) if actions[action] then actions[action](Player,...) else error("Unknown action '" .. tostring(action) .. "'") end end)
-- --
|
|
|
| Report Abuse |
|
|
|
| 24 Jan 2016 06:32 AM |
I actually want players to see each others' characters. Optimistically it will add a challenge to the game. player A and player B will have a different obby, and when player B sees player A doing different things they might try to mimic them, getting their character killed, hopefully distracting them from making the game too easy. You know, not trusting their eyes lol
A for the rest, chim you did it again. You seem to be the only real player around here that I can rely on. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 24 Jan 2016 06:46 AM |
You have to be careful with replicated characters and local parts. Roblox's physics networking is weird and causes the other characters to interact with parts that only exist for you. They won't notice anything but if you have any loose parts and they walk through them they could be moved.
|
|
|
| Report Abuse |
|
|
|
| 24 Jan 2016 10:14 AM |
| I thought about that before you even said anything but I'm happy that you confirmed it for me and I already took preventative measures by making sure everything is anchored and using cframe to move instead. |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2016 10:33 AM |
I have a quick question before I finish up. The 3 dots. What are these and why are these? lol
If I had to take a guess from the context in which you used them, they appear to me to be some sort of... idk dynamic tabling method?
I've honestly never seen these before or even heard of them. I tried looking it up on the wiki but apparently "three dots" or "3 periods" doesn't have any results. Just another example of why the wiki sucks. If people don't know what they're looking for, they're never going to find it. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 24 Jan 2016 11:05 AM |
"..." is used for vararg functions. It represents all arguments passed after the previous parameter. You can get the values out of it two ways.
For example:
a = function(...) local b,c,d = ... -- sets b to the first argument, c to the second, and d to the third print(b,c,d) end
a(1) --> 1 nil nil a(1,2) --> 1 2 nil a(1,2,3) --> 1 2 3 a(1,2,3,4) -- 1 2 3
b = function(...) local values = {...} -- convert it into an array local b,c,d = values[1],values[2],values[3] print(b,c,d) end
--
http://www.lua.org/manual/5.1/manual.html#2.5.9
However, in the function for "action" I was using it as a placeholder for any parameters you would want.
|
|
|
| Report Abuse |
|
|
| |
|
|
| 25 Jan 2016 03:02 PM |
| hey chim i just thought of something that seemed really important to ask about. If I'm using FilteringEnabled, do I want the server script to build the obby for each player if I want it localized to the client, or should I fire back to the client and have the LocalScript build it? |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 25 Jan 2016 03:39 PM |
If you want each player to have a different thing, you will want to create it from a local script.
|
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 04:28 PM |
| That's what I thought. Hey I'm gonna send you a pm soon about the game. Hopefully you'll say yes |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 04:29 PM |
| nvm messages turned off. Actually I was wondering if after I get the framework of the game finished if you'd be kind enough to tidy it up for me since you're so good at this sort of thing. I can only do what i can with what I know. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
| |
|
|
| 25 Jan 2016 05:01 PM |
I'm glad to hear that, but for now I've already hit another error. That table setup you gave me so that I can use one remote event to handle different functions, I tried to apply that to the LocalScript as well.
local actions = { ["Play"] = function(Player, ...) Trigger:FireClient(Player, "Setup") end }
in the server script, and
game.StarterGui:SetCoreGuiEnabled(4, false) local RepStore = game.ReplicatedStorage local Player = game.Players.LocalPlayer local Trigger = RepStore["Event Handler"]
local Menu = RepStore.Guis["Main Menu"]:Clone() Menu.Parent = game.Players.LocalPlayer.PlayerGui
Menu.Frame.PlayButton.MouseButton1Click:connect(function()
RepStore["Event Handler"]:FireServer("Play") Menu:Destroy()
end)
function CheckForAction(Parent) local Act = Parent:findFirstChild("Action") if Act then Act.Disabled = false end end
local actions = { ["Setup"] = function(Player, ...) local Opo = game.Workspace:findFirstChild(Player.Name.. "'s Obby") if Opo then Opo:Destroy() else local PO = Instance.new("Folder", game.Workspace) PO.Name = Player.Name.. "'s Obby" local Start = RepStore.Checkpoint:Clone() Start.PrimaryPart = Start.Primary Start:SetPrimaryPartCFrame(CFrame.new(0, 0, 0)) Start.Parent = PO local Course = {}
for i = 1, 5 do local Obbys = RepStore.Resources:GetChildren() local NewO = Obbys[math.random(1,#Obbys)]:Clone() NewO.PrimaryPart = NewO.Primary if i == 1 then NewO:SetPrimaryPartCFrame(Start.PrimaryPart.CFrame * CFrame.new(0, 0, ((Start.PrimaryPart.Size.Z/2) + (NewO.PrimaryPart.Size.Z/2)))) NewO.Parent = PO
end end
end end }
Trigger.OnClientEvent:connect(function(Player,action, ...) if actions[action] then actions[action](Player,...) else error("Unknown action '" .. tostring(action) .. "'") end end)
I didn't finish the actual function because it's only set up to test the position of where the obbys are getting placed, but it's throwing me an error:
16:57:55.946 - Players.Player1.PlayerScripts.Client Handler:49: Unknown action 'nil' 16:57:55.948 - Script 'Players.Player1.PlayerScripts.Client Handler', Line 49 16:57:55.948 - Stack End
which is the error that was printed from the LocalScript
So apparently I messed up something in the FireClient() function and it's not sending the name or something. I have no idea. This is all new stuff for me. |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 05:16 PM |
I did something
Trigger.OnClientEvent:connect(function(action, ...) if actions[action] then actions[action](...) else error("Unknown action '" .. tostring(action) .. "'") end end)
that seemed to fix the error, but now...
17:14:45.254 - Players.Player1.PlayerScripts.Client Handler:22: attempt to index local 'Player' (a nil value) 17:14:45.254 - Stack Begin 17:14:45.254 - Script 'Players.Player1.PlayerScripts.Client Handler', Line 22 - field ? 17:14:45.254 - Script 'Players.Player1.PlayerScripts.Client Handler', Line 48 17:14:45.254 - Stack End
As if the variable at the top of the script didn't get the player. |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 05:19 PM |
| I figured that one out pretty easily. I need to change the variable calling for the player. There are 2 of them with the same name. |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 05:20 PM |
lol nothing to see here folks, everything was fixed :3
for now anyway lmao... knowing me i'll mess something up in the future. I'll keep ya posted, buddy |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 05:30 PM |
ok so now that everything was fixed I've hit another roadblock
for i = 1, 5 do local Obbys = RepStore.Resources:GetChildren() local NewO = Obbys[math.random(1, #Obbys)]:Clone() NewO.PrimaryPart = NewO.Primary if i == 1 then NewO:SetPrimaryPartCFrame(Start.PrimaryPart.CFrame * CFrame.new(0, 0, ((Start.PrimaryPart.Size.Z/2) + (NewO.PrimaryPart.Size.Z/2)))) NewO.Parent = PO else NewO:SetPrimaryPartCFrame(Start.PrimaryPart.CFrame * CFrame.new(0, 0, ((Start.PrimaryPart.Size.Z/2) + (NewO.PrimaryPart.Size.Z/2)))) NewO.Parent = PO
end end
idea behind this for loop was to randomly pick a course and place it. each course is a 40 by 40 course with varying depths since each course is different. First the function places the start, or the checkpoint as i call it, then if i == 1, it picks a random obby and places it in front of the start. then comes the else argument... and apparently I did something that prevents me from being able to place course #2 in front of course #1.
In my brain I was thinking something like course 2 cframe = NewO[i-1] cframe but I don't think that can work. it throws me an error saying 2 is not a valid member of resources, which is the folder in ReplicatedStorage that holds the courses. So it's calling for a number, not an object and I have no idea how to fix it. I had to undo everything to get it back to what you see now. |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 05:32 PM |
NewO:SetPrimaryPartCFrame(Start.PrimaryPart.CFrame * CFrame.new(0, 0, ((Start.PrimaryPart.Size.Z/2) + (NewO.PrimaryPart.Size.Z/2)))) NewO.Parent = PO
There are two of these, and it's the second one that comes after the 'else' that I need to edit to allow the rest of the for loop to continue. It needs to SetPrimaryPartCFrame() in front of each previous course. |
|
|
| Report Abuse |
|
|
| |
|
|
| 26 Jan 2016 12:28 PM |
| well i've spent all night on this and I can't figure it out. I set it up to randomly pick one, but I guess in doing so I prevented myself from allowing the for loop to continue |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2016 12:44 PM |
Ok so I managed to fix the for loop, but now the courses won't position properly. Idk... the math looks fine to me. it makes perfect sense. The first one positions in front of the checkpoint at the proper distance, but the rest don't seem to want to cooperate.
game.StarterGui:SetCoreGuiEnabled(4, false) local RepStore = game.ReplicatedStorage local Plr = game.Players.LocalPlayer local Trigger = RepStore["Event Handler"]
local Menu = RepStore.Guis["Main Menu"]:Clone() Menu.Parent = game.Players.LocalPlayer.PlayerGui
Menu.Frame.PlayButton.MouseButton1Click:connect(function()
RepStore["Event Handler"]:FireServer("Play") Menu:Destroy()
end)
function CheckForAction(Parent) local Act = Parent:findFirstChild("Action") if Act then Act.Disabled = false end end
local actions = { ["Setup"] = function(Player, ...) local Opo = game.Workspace:findFirstChild(Plr.Name.. "'s Obby") if Opo then Opo:Destroy() else local PO = Instance.new("Folder", game.Workspace) PO.Name = Plr.Name.. "'s Obby" local Start = RepStore.Checkpoint:Clone() Start.PrimaryPart = Start.Primary Start:SetPrimaryPartCFrame(CFrame.new(0, 0, 0)) Start.Parent = PO local Course = {}
local PrevO = nil
for i = 1, 5 do local Obbys = RepStore.Resources:GetChildren() local NewO = Obbys[math.random(1,#Obbys)]:Clone() NewO.PrimaryPart = NewO.Primary if i == 1 then NewO:SetPrimaryPartCFrame(Start.PrimaryPart.CFrame * CFrame.new(0, 0, ((Start.Primary.Size.Z/2) + (NewO.Primary.Size.Z/2)))) NewO.Parent = PO PrevO = NewO else NewO:SetPrimaryPartCFrame(Start.PrimaryPart.CFrame * CFrame.new(0, 0, ((PrevO.Primary.Size.Z/2) + (NewO.Primary.Size.Z/2)))) NewO.Parent = PO PrevO = NewO end end
end end }
Trigger.OnClientEvent:connect(function(action, ...) if actions[action] then actions[action](...) else error("Unknown action '" .. tostring(action) .. "'") end end)
|
|
|
| Report Abuse |
|
|
|
| 26 Jan 2016 03:37 PM |
Ok I added print lines to tell me if things were being called correctly and they were. The PrimaryParts are all the same size for now: 40, 1, 40 but for some reason only the first course gets placed correctly. numbers 2 through 5 are supposed to also get moved 40 studs in front according to the math but are for some reason only moving about 10 studs in front. On top of that, course 2 through 5 are getting positioned in the exact same spot in workspace.
I am at an absolute loss at this point. Everything looks just fine to me but it isn't working properly. I simply don't understand why.
game.StarterGui:SetCoreGuiEnabled(4, false) local RepStore = game.ReplicatedStorage local Plr = game.Players.LocalPlayer local Trigger = RepStore["Event Handler"]
local Menu = RepStore.Guis["Main Menu"]:Clone() Menu.Parent = game.Players.LocalPlayer.PlayerGui
Menu.Frame.PlayButton.MouseButton1Click:connect(function()
RepStore["Event Handler"]:FireServer("Play") Menu:Destroy()
end)
function CheckForAction(Parent) local Act = Parent:findFirstChild("Action") if Act then Act.Disabled = false end end
local PrevO = nil
local actions = { ["Setup"] = function(Player, ...) local Opo = game.Workspace:findFirstChild(Plr.Name.. "'s Obby") if Opo then Opo:Destroy() else local PO = Instance.new("Folder", game.Workspace) PO.Name = Plr.Name.. "'s Obby" local Start = RepStore.Checkpoint:Clone() Start.PrimaryPart = Start.Primary Start:SetPrimaryPartCFrame(CFrame.new(0, 0, 0)) Start.Parent = PO PrevO = Start local Course = {}
print(PrevO)
for i = 1, 5 do wait(5) local Obbys = RepStore.Resources:GetChildren() local NewO = Obbys[math.random(1,#Obbys)]:Clone() NewO.PrimaryPart = NewO.Primary if i == 1 then NewO.Parent = PO NewO:SetPrimaryPartCFrame(Start.PrimaryPart.CFrame * CFrame.new(0, 0, ((PrevO.PrimaryPart.Size.Z/2) + (NewO.PrimaryPart.Size.Z/2)))) print("----") print(NewO) print(PrevO) PrevO = NewO else NewO.Parent = PO NewO:SetPrimaryPartCFrame(Start.PrimaryPart.CFrame * CFrame.new(0, 0, ((PrevO.PrimaryPart.Size.Z/2) + (NewO.PrimaryPart.Size.Z/2)))) print("----") print(NewO) print(PrevO) PrevO = NewO end end
end end }
Trigger.OnClientEvent:connect(function(action, ...) if actions[action] then actions[action](...) else error("Unknown action '" .. tostring(action) .. "'") end end) |
|
|
| Report Abuse |
|
|