so im using remote event to do a script. Server Script
1 | local event = game.ReplicatedStorage.RemoteEvent |
2 | local part = workspace [ "potty button" ] |
3 | part.Touched:Connect( function (Player) |
4 | event:FireServer() |
5 | end ) |
Local Script(in startergui)
1 | local event = game.ReplicatedStorage.RemoteEvent |
2 | local plr = game.Players.LocalPlayer |
3 | event.OnServerEvent:Connect( function () |
4 | local stats = plr:WaitForChild( "leaderstats" ) if stats then |
5 | local fullness = stats:FindFirstChild( "Fullness" ) if fullness then |
6 | fullness.Value = 0 |
7 | end |
8 | end |
9 | end ) |
It says theres an error in the server script that says
FireServer can only be called from client
. What does this mean and can someone help?
You can only use :FireServer()
with LocalScript and only use OnServerEvent
with ServerScript, and you can get player/change player stats with .Touched
Example:
01 | script.Parent.Touched:Connect( function (hit) -- Get hit part |
02 | if hit.Parent:FindFirstChild( "Humanoid" ) then -- If find humanoid |
03 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Get the player from character |
04 | if player then -- Check player |
05 | print ( "Correct!" ) |
06 | else |
07 | print ( "Error!" ) |
08 | end |
09 | end |
10 | end ) |
Here is fixed script:
01 | -- Removed RemoteEvent, you dont need this |
02 | local part = workspace:WaitForChild( "potty button" ) -- Added a WaitForChild |
03 |
04 | part.Touched:Connect( function (hit) -- Changed Player to hit |
05 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
06 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
07 | if player then |
08 | local stats = player:WaitForChild( "leaderstats" ) |
09 | if stats then |
10 | local fullness = stats:FindFirstChild( "Fullness" ) |
11 | if fullness then |
12 | fullness.Value = 0 |
13 | end |
14 | end |
15 | end |
16 | end |
17 | end ) |
If you change per client the server does not receive the information.
Wiki pages:
Learn more of Remote Events / Functions: Remote Events/Functions