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

[SOLVED]It says FireServer can only be called from client?

Asked by 6 years ago
Edited 6 years ago

so im using remote event to do a script. Server Script

1local event = game.ReplicatedStorage.RemoteEvent
2local part = workspace["potty button"]
3part.Touched:Connect(function(Player)
4    event:FireServer()
5end)

Local Script(in startergui)

1local event= game.ReplicatedStorage.RemoteEvent
2local plr = game.Players.LocalPlayer
3event.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
9end)

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?

0
it won't work since you're calling FireServer on the server Bean_dinosaur 42 — 6y

1 answer

Log in to vote
1
Answered by
yHasteeD 1819 Moderation Voter
6 years ago
Edited 6 years ago

You can only use :FireServer() with LocalScript and only use OnServerEvent with ServerScript, and you can get player/change player stats with .Touched Example:

01script.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
10end)

Here is fixed script:

01-- Removed RemoteEvent, you dont need this
02local part = workspace:WaitForChild("potty button") -- Added a WaitForChild
03 
04part.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
17end)

If you change per client the server does not receive the information.

Wiki pages:

WaitForChild()

GetPlayerFromCharacter

Touched

Learn more of Remote Events / Functions: Remote Events/Functions

Hope it helped :D

Solved your problems? put in title [SOLVED] or accept a answer.
0
TYSM!! nzsalty16 81 — 6y
Ad

Answer this question