Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

1 comment

0

it won't work since you're calling FireServer on the server

1 answer

✓ Accepted answer

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.

1 comment

0

TYSM!!

This discussion is preserved as it was. New answers, comments, and votes are closed.