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

A local script not configuring a player stats?

Here's the script that's causing the problem.

local rep = game:GetService("ReplicatedStorage")
local playerBobux = game.Players.LocalPlayer.leaderstats.BOBUX.Value

script.Parent.MouseButton1Click:Connect(function()
	local glock = rep.G17
	
	if playerBobux > 49.99 then
		local glockclone = glock:Clone()
		
		glockclone.Parent = game.Players.LocalPlayer.Backpack
		playerBobux = playerBobux - 50
	end
end)

Its a script in a button however when I click the button my BOBUX doesn't change or getting the gun, also the output doesn't have any errors. So, unfortunately, I cannot show an error. Can someone please help me with this problem?

1 answer

✓ Accepted answer

You dont change values on the client. You have to use remote events and sanity checks on the server.

An example of how you would do that

SERVER SIDE

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Event

Event.OnServerEvent:Connect(function(Player) --server received event
	local Bobux = Player.Bobux --path to your number value
	
	-- if 50 is bigger than numbervalue
	if Bobux.Value < 50 then --this is a sanity check
		return --lets return 
	end 
	
	--if number value is bigger or equal to 50 then
	Bobux.Value -= 50 --we can use -= so its like Bobux.Value = Bobux.Value - 50
end)

CLIENT SIDE

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Event

Button.MouseButton1Down:Connect(function()
	Event:FireServer() --lets fire to the server
end)

1 comment

0

Thanks a bunch!

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