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?
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:
Learn more of Remote Events / Functions: Remote Events/Functions