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

FireServer can only be called from the client? Please help!

I'm working on a simulator and this is a script for a UpgradeGui. On line 7 is where the error is. If someone helps it would be really helpful!

Thanks, notreallysupernova

--[[ First, put a RemoteEvent in Replicated Storage before doing any of this.
	]]
-- Client/Local Script:
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

script.Parent.MouseButton1Down:Connect(function()
	remoteEvent:FireServer() -- This is the error
end)

-- Server/Normal Script:
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local OwnUpgrade = game.ReplicatedStorage.Stats.OwnMoreCars
local CarRespawn = game.ReplicatedStorage.Stats.CarRespawn
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("OwnMoreCarsSaver")
local players = game:GetService("Players")

players.PlayerAdded:connect(function(player)
	OwnUpgrade.Value = ds1:GetAsync(player.UserId) or false
	ds1:SetAsync(player.UserId, OwnUpgrade.Value)
end)

if OwnUpgrade.Value == true then
	CarRespawn.Value = CarRespawn.Value - 1
	OwnUpgrade.Value = true
	print("Owned Upgrade")
	
	script.Parent:Destroy()
end

local player = remoteEvent.OnServerEvent:Wait()
local leaderstats = player:WaitForChild("leaderstats",7)
local Money = leaderstats:WaitForChild("Money")




local price = 300
if Money.Value >= price then
	Money.Value -= price
	print("Purchased")
	CarRespawn.Value = CarRespawn.Value - 1
	OwnUpgrade.Value = true
	
	ds1:SetAsync(player.UserId, OwnUpgrade.Value)
	script.Parent:Destroy()
	
end

2 answers

✓ Accepted answer

Ok, so you're using my script. Maybe you didn't really quite understand. Put this in a LOCAL SCRIPT, (LocalScript object)

 Client/Local Script:
	local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
	 
	script.Parent.MouseButton1Down:Connect(function()
	    remoteEvent:FireServer() -- This is the error
	end)

If you don't know what local scripts are, search in google.

This is the part that goes in SERVER/NORMAL script, (Script object)

-- Server/Normal Script:
	local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
	local OwnUpgrade = game.ReplicatedStorage.Stats.OwnMoreCars
	local CarRespawn = game.ReplicatedStorage.Stats.CarRespawn
	local datastore = game:GetService("DataStoreService")
	local ds1 = datastore:GetDataStore("OwnMoreCarsSaver")
	local players = game:GetService("Players")
	 
	players.PlayerAdded:connect(function(player)
	    OwnUpgrade.Value = ds1:GetAsync(player.UserId) or false
	    ds1:SetAsync(player.UserId, OwnUpgrade.Value)
	end)
	 
	if OwnUpgrade.Value == true then
	    CarRespawn.Value = CarRespawn.Value - 1
	    OwnUpgrade.Value = true
	    print("Owned Upgrade")
	 
	    script.Parent:Destroy()
	end
	 
	local player = remoteEvent.OnServerEvent:Wait()
	local leaderstats = player:WaitForChild("leaderstats",7)
	local Money = leaderstats:WaitForChild("Money")	 
	 
	local price = 300
	if Money.Value >= price then
	    Money.Value -= price
	    print("Purchased")
	    CarRespawn.Value = CarRespawn.Value - 1
	    OwnUpgrade.Value = true
	 
	    ds1:SetAsync(player.UserId, OwnUpgrade.Value)
	    script.Parent:Destroy()
	 
	end

Basically, put them in separate scripts. Script in ServerScriptService, LocalScript inside the gui object. Please understand or add me in discord Crowthebird#1649.

The FireServer function can only be called on upon a localscript. Server scripts or normal scripts use the FireClient and FireAllClients function. The fire server is just really called as from a remote event and so the client can send data to the server that the remote has been fired.

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