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;

1script.Parent.MouseButton1Down:Connect(function()
2        local player = game.Players.LocalPlayer
3        local takeme = script.Parent
4        local parto = player.Character.Part
5        local rm = game.ReplicatedStorage.RemoteEvent
6        wait(.1)
7        rm:FireServer(player,parto,takeme)
8        print 'fired!'
9 end)

Server;

01local rm = game.ReplicatedStorage.RemoteEvent
02rm.OnServerEvent:Connect(function(player,parto,takeme)
03    print 'does it print?'
04    local player = game.Players.LocalPlayer
05    local takeme = script.Parent
06    local parto = player.Character:WaitForChild("Part")
07    if parto then
08    print 'part recognised'
09    local parta = player.Character.Part
10    local nyee = parta.BillboardGui.NAME
11    nyee.Text = (nyee.Text.. " | ")
12    print 'text applied'
13end
14end)

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:

1rm:FireServer(player,parto,takeme)

you have to do:

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

1local takeme = script.Parent
2local rm = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
3 
4takeme .MouseButton1Down:Connect(function()
5    local parto = player.Character.Part
6    rm:FireServer(parto, takeme)
7    print("Fired Server")
8 end)

Global Script:

01local rm = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
02 
03rm.OnServerEvent:Connect(function(player, parto, takeme)
04    print("Server Got Signal")
05    if parto then
06        print("Part Recognised")
07        local nyee = parto.BillboardGui.NAME --It would be better if you changed this, since "Name" is also a property of the BillboardGui class.
08        nyee.Text = (nyee.Text.. " | ")
09        print("Text Changed")
10    end
11end)

Answer this question