Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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.

0
what is HackerLightEnter Bean_dinosaur 42 — 6y

2 answers

Log in to vote
0
Answered by
Hizar7 102
6 years ago

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

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 ^-^ xXDoneBeingCoolXx 33 — 6y
0
If it helped you why don't you accept his/her answer. Both of you will get +rep :) SirDerpyHerp 262 — 6y
0
It isn't working sadly. xXDoneBeingCoolXx 33 — 6y
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 Hizar7 102 — 6y
View all comments (6 more)
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 Hizar7 102 — 6y
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. xXDoneBeingCoolXx 33 — 6y
0
'attempt to index local 'value' (a nil value)' xXDoneBeingCoolXx 33 — 6y
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 Hizar7 102 — 6y
0
dude u should have stuckto unity things better TheluaBanana 946 — 6y
0
Edited code at the bottom that works :v xXDoneBeingCoolXx 33 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)

Answer this question