You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
The idea is that I can use a screen GUI control panel to control an NPCS movements through the humanoid such as jump, targeting enemy NPC, follow, etc.
What is the issue? Include screenshots / videos if possible!
First of all, I’m not really that experienced with using remote events, so sorry if I’m missing something. Anyway, when two players play the game with the control panel for the NPCs if one player clicks the “Jump” button on the control panel GUI it makes both NPCS jump, which I assume is because it’s firing it through the server somehow on all clients?? Again, I’m not really sure.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried looking on the dev forum for similar issues but nothing has seemed to help me just yet. I’ve also tried re reading the Remote Functions and Events article ROBLOX has posted on the DevHub but didn’t really get much out of it.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Code:
Local:
local RPS = game.ReplicatedStorage
local Remote = RPS.Events.Toy:WaitForChild("ToyGui")
script.Parent.MouseButton1Click:Connect(function()
local plr = game:GetService("Players").LocalPlayer
if plr == game:GetService("Players").LocalPlayer then
Remote:FireServer(plr, print(plr))
end
end)
Server:
local tool = script.Parent
local RPS = game.ReplicatedStorage
local Remote = RPS.Events.Toy:WaitForChild("ToyGui")
local follow = true
Remote.OnServerEvent:Connect(function()
follow = false
script.Parent.ToyNoob.Attack.Disabled = true
script.Parent.ToyNoob.Damage.Disabled = true
print("toy jump event working")
local toy = script.Parent:FindFirstChild("ToyNoob")
toy.ToyHumanoid.Jump = true
toy.ToyHumanoid.WalkSpeed = 8
end)
I appreciate any help given, I’m not looking for any code spoon-feeding or anything just some insight. Thanks.
You don’t need to check if the LocalPlayer is the LocalPlayer. You don’t need to pass the LocalPlayer as a parameter in FireServer. For OnServerEvent, the Player parameter is passed, which you should generally define in the brackets/parenthesis.
I’m not sure if I misunderstood but is this what you meant?? The player parameter is already passed automatically? Sorry, I’m not sure if I’m doing this correctly or not.
Server:
Remote.OnServerEvent:Connect(function(plr)
if plr then
follow = false
script.Parent.ToyNoob.Attack.Disabled = true
script.Parent.ToyNoob.Damage.Disabled = true
print("toy jump event working")
local toy = script.Parent:FindFirstChild("ToyNoob")
toy.ToyHumanoid.Jump = true
toy.ToyHumanoid.WalkSpeed = 8
end
end)
Client:
local RPS = game.ReplicatedStorage
local Remote = RPS.Events.Toy:WaitForChild("ToyGui")
script.Parent.MouseButton1Click:Connect(function()
Remote:FireServer()
end)
When I click the “Jump” GUI button while two players have it equipped on one player’s client-side it causes both NPCs to jump. Sorry if it’s confusing.
Remote.OnServerEvent:Connect(function(plr)
follow = false
print("toy jump event working")
for _, toy in pairs(script.Parent:GetChildren()) do
if toy.Name == "ToyNoob" then
toy.Attack.Disabled = true
toy.Damage.Disabled = true
toy:WaitForChild("ToyHumanoid").Jump = true
toy:WaitForChild("ToyHumanoid").WalkSpeed = 8
end
end
end)
Sorry for the really laggy Gyazo clip but you should get the jist. This is a clip of two clients. If one player clicks the jump GUI button it makes both NPCs jump when it should only make one NPC jump. https://gyazo.com/1c6e7335223bd938896a4b190743198a
Yeah, just one. The NPC is inside a tool, so when you equip the tool the NPC spawns next to you. If there is only one player it works perfectly fine but if there are multiple players it seems to cause issues.
Example: Player1 and Player2 both have the tool equipped with two NPCs spawned in. Player 1 clicks the “Jump” button on their client-sided GUI panel. Both Player1 and Player2 NPCs jump.
When Player1 clicks the “Jump” button it’s supposed to only make Player1s NPC jump, not both Player1 and Player2s NPCs. Does this make sense?? Sorry for the confusion.