RemoteEvent Question

I am currently making the script that changes the color when player pressed the button, but while making this there is a problem. That changes another player’s vest color too. By looking I got it OnServerEvent but, I don’t know other one, so if you have any idea please tell me.

I just want to make this ONLY 1 PLAYER ABLE TO CHANGE.

remotes.OnServerEvent:Connect(function(plr,setremote)
	script.Parent.Lightsectionsvalues.Value = setremote
end)

remotes2.OnServerEvent:Connect(function(plr,setremote2)
	script.Parent.Colorset.Value = setremote2
end)

Can you explain this better please? I don’t understand what I just read.

if plr ~= yourPlayerInstance then return end

2 Likes

Can you explain whats is this about?

Okay. So, If I and someone other have same vest and there is a UI in the vest, if I pressed the UIButton it changes another player’s color too. Thats the problem.

Alright so, what I believe you are saying is… if the player wants to change their vest color, it changes it for them. But instead of doing it for just them, it does it for everyone in the server. Correct?

Also, if this is correct, I’d like to know what the value in your code is. Is it a Color3 value? BrickColor value? None of the above? We need a bit more detail than what you are showing us. Such as Output Messages that have errors, what values you’re trying to use, the code in the LocalScript and ServerScript. If you could send those kinds of images, or send us code in a lua code block, then that’d be amazing.

BrickColor, vest is giving by using the proxypromit so i had to clone and do that, but when 2 players gets vest and 1 of them press color button others changes too so i want to make this only 1.

local

local ColorsSetGreens = script.Parent.Frame.Colors.Greens

local ColorsSetRed = script.Parent.Frame.Colors.Red

local ColorsSetYellows = script.Parent.Frame.Colors.Yellows


local Lightupbuttons = script.Parent.Frame.Lightup

local Lightdownbuttons = script.Parent.Frame.LightDown

local Blightings = script.Parent.Frame.Bilights

local BlightsUP = "Bligings"

local Normals = "Normals"

local none = ""

local Greensup = "Greens"

local Redup = "Red"

local Yellowsup = "Yellows"


local RemoteColorsFired = game.ReplicatedStorage.VestEvents.ColorsEvent

local RemoteLightsFired = game.ReplicatedStorage.VestEvents.lightsevent



Lightupbuttons.MouseButton1Up:Connect(function()
	RemoteLightsFired:FireServer(Normals)
end)

Lightdownbuttons.MouseButton1Up:Connect(function()
	RemoteLightsFired:FireServer(none)
end)

Blightings.MouseButton1Up:Connect(function()
	RemoteLightsFired:FireServer(BlightsUP)
end)

ColorsSetGreens.MouseButton1Up:Connect(function()
	RemoteColorsFired:FireServer(Greensup)
end)

ColorsSetRed.MouseButton1Up:Connect(function()
	RemoteColorsFired:FireServer(Redup)
end)

ColorsSetYellows.MouseButton1Up:Connect(function()
	RemoteColorsFired:FireServer(Yellowsup)
end)

server


local remotes = game.ReplicatedStorage.VestEvents.lightsevent

local remotes2 = game.ReplicatedStorage.VestEvents.ColorsEvent


remotes.OnServerEvent:Connect(function(plr,setremote)
	script.Parent.Lightsectionsvalues.Value = setremote
end)

remotes2.OnServerEvent:Connect(function(plr,setremote2)
	script.Parent.Colorset.Value = setremote2
end)


script.Parent.Colorset.Changed:Connect(function()
	if script.Parent.Colorset.Value == "Greens" then
		script.Parent.Lightseffectionstest.BrickColor = BrickColor.new("Lime green")
		script.Parent.Lightseffectionstest.PointLight.Color = Color3.new(0.215686, 1, 0)
	elseif script.Parent.Colorset.Value == "Red" then
		script.Parent.Lightseffectionstest.BrickColor = BrickColor.new("Really red")
		script.Parent.Lightseffectionstest.PointLight.Color = Color3.new(1, 0, 0.0156863)
	elseif script.Parent.Colorset.Value == "Yellows" then
		script.Parent.Lightseffectionstest.BrickColor = BrickColor.new("New Yeller")
		script.Parent.Lightseffectionstest.PointLight.Color = Color3.new(1, 0.917647, 0.027451)
	end
end)

script.Parent.Lightsectionsvalues.Changed:Connect(function()
	if script.Parent.Lightsectionsvalues.Value == "Bligings" then
		script.Parent.Blitings.Enabled = true
	elseif script.Parent.Lightsectionsvalues.Value == "Normals" and script.Parent.Colorset.Value == "Greens" then
		script.Parent.Blitings.Enabled = false
		script.Parent.Lightseffectionstest.BrickColor = BrickColor.new("Lime green")
		script.Parent.Lightseffectionstest.PointLight.Color = Color3.new(0.215686, 1, 0)
		wait(0.5)
		script.Parent.Lightseffectionstest.PointLight.Brightness = 2
	elseif script.Parent.Lightsectionsvalues.Value == "Normals" and script.Parent.Colorset.Value == "Red" then
		script.Parent.Blitings.Enabled = false
		script.Parent.Lightseffectionstest.BrickColor = BrickColor.new("Really red")
		script.Parent.Lightseffectionstest.PointLight.Color = Color3.new(1, 0, 0)
		wait(0.5)
		script.Parent.Lightseffectionstest.PointLight.Brightness = 2
	elseif script.Parent.Lightsectionsvalues.Value == "Normals" and script.Parent.Colorset.Value == "Yellows" then
		script.Parent.Blitings.Enabled = false
		script.Parent.Lightseffectionstest.BrickColor = BrickColor.new("New Yeller")
		script.Parent.Lightseffectionstest.PointLight.Color = Color3.new(1, 0.917647, 0.027451)
		wait(0.5)
		script.Parent.Lightseffectionstest.PointLight.Brightness = 2
	elseif script.Parent.Lightsectionsvalues.Value == "None" then
		script.Parent.Blitings.Enabled = false
		wait(0.5)
		script.Parent.Lightseffectionstest.BrickColor = BrickColor.new("Smoky grey")
		script.Parent.Lightseffectionstest.PointLight.Brightness = 0
	end
end)

Where is this script located? (Max Charactersssssss)

LocalScript (AT Giver)
image
ReplicatedStorage SCRIPT
image

I clone the vest.

Any idea? Please… (30000 marc)

It looks like you are trying to make a system that is changing certain values globally. Perhaps adding a value to the player when they load with code like this:

game:GetService("Players").PlayerAdded:Connect(function(Player)
   local LightSelectionsValue = Instance.new("StringValue")
   local Colorset = Instance.new("StringValue")
   LightSelectionsValue.Parent = Player
   Colorset.Parent = Player
end)

Please be aware, it is hard for me to understand what Value type Lightselectionsvalue and Colorset value’s are, and you might need to change it to the name.

In the script you provided, please do the following:

remotes.OnServerEvent:Connect(function(plr,setremote)
	plr.Lightsectionsvalues.Value = setremote
end)

remotes2.OnServerEvent:Connect(function(plr,setremote2)
	plr.Colorset.Value = setremote2
end)

Please be aware, any code that relies on LightSelectionsValue and Colorset will need to be adjusted to work properly.

Let me know if you have any further questions.

1 Like

Sorry for such a late reply, I had to sleep. So, what I believe is happening is that you are putting this one event in ReplicatedStorage, and not actually parented to the vest. If you want things to happen for one Player only, you’d, like @Chat_GPT said, would need to parent your values/events into the player. Either that, or parent it to the vest. Afterwards, adjust your code as needed and parent your scripts to the need places.

1 Like

I tried that but it didn’t work what should I do now…

It changes all player’s color.

still why? i really want the solution

Why i dont get reply please tell

When you’re firing the remote it’s telling all vests to change because your code doesn’t specify to not change the vest if the remote isn’t fired from the specific player who’s vest color your trying to change. You need to add something that’ll prevent it from continuing the code if “plr” isn’t the same player the vest is under. Should look something like this,

remotes.OnServerEvent:Connect(function(plr,setremote)
if plr.Character ~= script.Parent.Parent then return end
	script.Parent.Lightsectionsvalues.Value = setremote
end)

remotes2.OnServerEvent:Connect(function(plr,setremote2)
if plr.Character ~= script.Parent.Parent then return end
	script.Parent.Colorset.Value = setremote2
end)

The script.Parent.Parent part is the character since I assume the vest is parented to the character. Obviously this isn’t the most eloquent solution and I would recommend not having there be a specific script for each vest but rather one serverscript that changes a specified vest, but this should work for what you have right now.

1 Like