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 5 years ago
Edited 5 years ago

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

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

Local Script(in startergui)

local event= game.ReplicatedStorage.RemoteEvent
local plr = game.Players.LocalPlayer
event.OnServerEvent:Connect(function()
    local stats = plr:WaitForChild("leaderstats") if stats then
        local fullness = stats:FindFirstChild("Fullness") if fullness then
            fullness.Value = 0
        end
    end
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?

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

1 answer

Log in to vote
1
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 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:

script.Parent.Touched:Connect(function(hit) -- Get hit part
    if hit.Parent:FindFirstChild("Humanoid") then -- If find humanoid
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Get the player from character
        if player then -- Check player
            print("Correct!")
        else
            print("Error!")
        end
    end
end)

Here is fixed script:

-- Removed RemoteEvent, you dont need this
local part = workspace:WaitForChild("potty button") -- Added a WaitForChild

part.Touched:Connect(function(hit) -- Changed Player to hit
   if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then
            local stats = player:WaitForChild("leaderstats")
            if stats then
                local fullness = stats:FindFirstChild("Fullness") 
                if fullness then
                    fullness.Value = 0
                end
            end
        end
    end
end)

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 — 5y
Ad

Answer this question