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

Server-side script in FE refuses to work, why?

Asked by
Talveka 31
6 years ago
Edited 6 years ago

Ive been at this for about a few hours now. A name GUI ive been working on just refuses to work. I know the client-side script works because it prints to the developer console in-game. The server-side script doesn't print anything, not even at the start.

Client;

script.Parent.MouseButton1Down:Connect(function()
        local player = game.Players.LocalPlayer
        local takeme = script.Parent
        local parto = player.Character.Part
        local rm = game.ReplicatedStorage.RemoteEvent
        wait(.1)
        rm:FireServer(player,parto,takeme)
        print 'fired!'
 end)

Server;

local rm = game.ReplicatedStorage.RemoteEvent
rm.OnServerEvent:Connect(function(player,parto,takeme)
    print 'does it print?'
    local player = game.Players.LocalPlayer
    local takeme = script.Parent
    local parto = player.Character:WaitForChild("Part")
    if parto then
    print 'part recognised'
    local parta = player.Character.Part
    local nyee = parta.BillboardGui.NAME
    nyee.Text = (nyee.Text.. " | ")
    print 'text applied'
end
end)

There's a custom part inside the player, which includes a BillboardGUI. The script should add a " | " symbol to the existing text of the Textbutton inside the BillboardGUI.

0
Line 11 shouldn't be wrapped in brackets. User#19524 175 — 6y
1
when you use the client functions for remote events / functions you should not add the player. Roblox adds the player as the first arg for you in OnServerEvent and removing the player from FireServer should fix the code. User#5423 17 — 6y
0
^ User#19524 175 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Your problem is on line 7 of your LocalScript. You're adding an extra argument to FireServer. Remove the player argument, and it should work.

Ad
Log in to vote
0
Answered by
Aorda 43
6 years ago

On the server side, you can't do "LocalPlayer" because the code is not in any player. Instead, you have to use the "player" parameter in the global script.

Also, while using "FireServer", you don't need to define the player again because it automatically does that.

so when you do this on the local script:

rm:FireServer(player,parto,takeme)

you have to do:

rm.OnServerEvent:Connect(function(player,player,parto,takeme)

or you can just not add the "player" parameter in the local script.

Also, you have another mistake in the global script which is: "local takeme = script.Parent". In the global script, script.Parent is no longer takeme and why are you defining it again? On the Server Side, you can't and don't need to define local stuff.

Here are the full fixed codes:

Local Script:

local takeme = script.Parent
local rm = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

takeme .MouseButton1Down:Connect(function()
    local parto = player.Character.Part
    rm:FireServer(parto, takeme)
    print("Fired Server")
 end)

Global Script:

local rm = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

rm.OnServerEvent:Connect(function(player, parto, takeme)
    print("Server Got Signal")
    if parto then
        print("Part Recognised")
        local nyee = parto.BillboardGui.NAME --It would be better if you changed this, since "Name" is also a property of the BillboardGui class.
        nyee.Text = (nyee.Text.. " | ")
        print("Text Changed")
    end
end)

Answer this question