Problem with Control Panel Remote Event

You can write your topic however you want, but you need to answer these questions:

  1. 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.

  1. 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.

  1. 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.

4 Likes

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)


Almost exactly what I meant, but you don’t have to do the if plr then statement.

Am I doing something else wrong? I still have the same results.

Does any NPC jump? Just one?

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.

FindCharacterFromPlayer will works where player’s model is.

ToyGui not in surface gui or your player gui is weird point.

So it causes both NPCs to jump but on one client’s side only?

Yeah, that’s right. I’m not sure if I need to specify the model to differentiate it between other NPCs??

Try this…

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)

Still the same. It doesn’t make a difference that the NPC Model is under a tool, does it?

Do you mean GetPlayerFromCharacter??

Let me get this clear, it only replicates its actions on a single client, although there are multiple? Which client would this be?

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

You should echo action to all of clients, right?

I think it’s firing to all clients when I want it to fire to only one client.

Oh… now I get it. You only want 1 to jump. And would it be random or only one NPC?

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.

I didn’t see a tool in the video, can you show it to us, with the full script for the tool?