Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Hello, I am wondering how I can send data from client to server. What am I doing wrong?

First off, I'll share my scripts for you to understand a little better.

Client:

local event = game.ReplicatedStorage.Events.HackerChangeColor
local button = script.Parent
local value = script.Parent.Parent.HackerLightEnter

button.MouseButton1Click:Connect(function()
	event:FireServer(value)
end)

Server:

local event = game.ReplicatedStorage.Events.HackerChangeColor

event.OnServerEvent:Connect(function(plr, value)
	for i, v in pairs(workspace:GetChildren()) do
		if v:IsA("Part") or v:IsA("UnionOperation") or v:IsA("MeshPart") then
			if v.Material == Enum.Material.Neon then
				v.BrickColor = BrickColor.new(value.text)
			end
		end
	end
end)

In this case, I'm attempting to send the instance known as 'value' from a LocalScript to a Server script. For some reason this isn't working, and I'd like some advice or anything really as to how I can fix this. If you need more detail, please say so, this is one of my first posts so.

1 comment

0

what is HackerLightEnter

2 answers

✓ Accepted answer

you need to have the fireserver event for the remote function like this

local script

game.ReplicatedStorage.RemoteEvent:FireServer(value)

and inside your server script you need to have it like this

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,value)

Hopefully this helped

10 comments

0

Oh O o F .. Sorry, I'm returning back to Roblox Lua after C# with Unity, so it's been weird. Thank you though ^-^

0

If it helped you why don't you accept his/her answer. Both of you will get +rep :)

0

It isn't working sadly.

0

that should be the exact way to get the information shared between a local script to a server script. make sure your placement for the line is in the right place for both of the scripts

0

Also incase you are forgetting this, my "RemoteEvent" is named exactly that, make sure in replicated storage your remoteevent is named exactly what you name it in the scripts

0

I edited the code above to what I now have. I still see nothing wrong with it, I've looked up so much in the past 2 hours or so just trying to find an answer. Still nothing.

0

'attempt to index local 'value' (a nil value)'

0

I'm not entirely sure, If that error is from the server script then it is sending the information from the client to the server, You'll have to figure out why the value is not existing

0

dude u should have stuckto unity things better

0

Edited code at the bottom that works :v

Fixed! I can't edit the properties of a variable sent from the client to the server, which is what I was trying to do on line 7

  v.BrickColor = BrickColor.new(value.text)

I fixed this by making the 'value' variable inside of the LocalScript From this:

local value = script.Parent.Parent.HackerLightEnter

To this:

local value = script.Parent.Parent.HackerLightEnter.Text

Meaning the code that works would be: SERVER:

local event = game.ReplicatedStorage.Events.HackerChangeColor
	 
	event.OnServerEvent:Connect(function(plr, value)
	    for i, v in pairs(workspace:GetChildren()) do
	        if v:IsA("Part") or v:IsA("UnionOperation") or v:IsA("MeshPart") then
	            if v.Material == Enum.Material.Neon then
	                v.BrickColor = BrickColor.new(value)
	            end
	        end
	    end
	end)

CLIENT:

	local event = game.ReplicatedStorage.Events.HackerChangeColor
	local button = script.Parent
	local value = script.Parent.Parent.HackerLightEnter.Text
	 
	button.MouseButton1Click:Connect(function()
	    event:FireServer(value)
	end)

This discussion is preserved as it was. New answers, comments, and votes are closed.