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

Why won't it give me 100 bux when i pull the gun out?

Here are the leaderstats in ServerScriptStorage

game.Players.PlayerAdded:Connect(function(plr)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = plr
	
	local Bux = Instance.new("IntValue")
	Bux.Parent = stats
	Bux.Name = "Bux"
	Bux.Value = 0
end)

Here is the script in StarterPack

script.Parent.Equipped:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer()
end)

And here is the script also in ServerScriptStorage

local player = game.Players.LocalPlayer
game.ReplicatedStorage.RemoteEvent:FireClient(function()
		player.leaderstats.Bux.Value = 100
end)

Error is Unable to cast value to Object

1 answer

✓ Accepted answer

Hello!

The first error you made was trying to get the LocalPlayer in a normal script by doing game.Players.LocalPlayer. You can't do that, you can only do that in a LocalScript. Also, you tried to fire the client when you fired the server. You should be using OnServerEvent. Below is a script that should help you.

game.ReplicatedStorage.OnServerEvent:Connect(function(player)
        player:WaitForChild("leaderstats").Bux.Value = player:WaitForChild("leaderstats").Bux.Value + 100
end)

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