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

How to fix all my errors in my sell button for my simulator?

So I am making a simulator and trying to make a saving leaderstats! The settings for my game are on but when I sell it will not set my value to others just me so when I go in dev console and print my money it shows I have 300 but I really only have 0!

Theres no errors but it wont give the money to the server side just the client kinda like what hacks do.

local leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats")
local PlayerStats = leaderstats.Parent:WaitForChild("PlayerStats")

game.ReplicatedStorage.Events.SellSugar.OnClientEvent:connect(function(plr) -- Change if event is in different area
	if leaderstats.Sugar.Value ~= 0 then
		local Cash = leaderstats:WaitForChild("Money")
        local Backpack = leaderstats:WaitForChild("Sugar")
        local multi = leaderstats.Parent:WaitForChild("PlayerStats").SellBonus
        Cash.Value = Cash.Value + multi.Value * Backpack.Value
        Backpack.Value = 0
		script.Earned:Play()
end
	
end)

1 answer

Dis was written on a tablet, so stick with me here. If there are any problems, comment them to me

You will want to use a RemoteEvent

More Info Here: https://developer.roblox.com/en-us/api-reference/class/RemoteEvent)

Anyways, the reason it's only showing client-sided is, well, your editing it on the client!

local leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats") local PlayerStats = leaderstats.Parent:WaitForChild("PlayerStats")

Local Script

game.ReplicatedStorage.Events.SellSugar.OnClientEvent:connect(function(plr)
	if leaderstats.Sugar.Value ~= 0 then
		game.ReplicatedStorage.Events.SellSugar.Sell:FireServer(Cash.Value,multi.Value,Backpack.Value)
local Cash = leaderstats:WaitForChild("Money")
		local Backpack = leaderstats:WaitForChild("Sugar")
		local multi = leaderstats.Parent:WaitForChild("PlayerStats").SellBonus
		Cash.Value = Cash.Value + multi.Value * Backpack.Value
		Backpack.Value = 0
        	script.Earned:Play()
	end
end)

Server Script

game.ReplicatedStorage.Events.SellSugar.Sell.OnServerEvent:Connect(function(plr,cash,multi,backpack)
	local leaderstats = plr:WaitForChild("leaderstats")
	local Cash = leaderstats:WaitForChild("Money")
	local Backpack = leaderstats:WaitForChild("Sugar")
	local multi = leaderstats.Parent:WaitForChild("PlayerStats").SellBonus
	Cash.Value = Cash.Value + multi.Value * Backpack.Value
end)

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