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

Script adding 32 to value instead of 16?

So I have a server script here:

local starblox = game.Teams["Starblox Employee"]

game.Workspace.Starblox.Working.Touched:Connect(function(hit)
	if hit.Parent.Parent:FindFirstChild("Humanoid") then
		if game.Players:FindFirstChild(hit.Parent.Parent.Name).Team == starblox then
			game.ReplicatedStorage.StarbloxStart:FireClient(game.Players:FindFirstChild(hit.Parent.Parent.Name))
			game.Players:FindFirstChild(hit.Parent.Parent.Name).Shift.Value = true
			script.Parent.Paycheck.Disabled = false
		else
			local hmm = hit.Parent.Parent.Name
			local col = game.Players:FindFirstChild(hmm)

			game.ReplicatedStorage.StarbloxAdd:FireAllClients(col)
		end
	end
end)

game.Workspace.Starblox.End.Touched:Connect(function(hit)
	if hit.Parent.Parent:FindFirstChild("Humanoid") then
		if game.Players:FindFirstChild(hit.Parent.Parent.Name).Team == starblox then
			if hit.Parent.Parent:FindFirstChild("Humanoid") then
				game.ReplicatedStorage.StarbloxEnd:FireClient(game.Players:FindFirstChild(hit.Parent.Parent.Name))
				game.Players:FindFirstChild(hit.Parent.Parent.Name).Shift.Value = false
				script.Parent.Paycheck.Disabled = true
			else
				local hmm = hit.Parent.Parent.Name
				local col = game.Players:FindFirstChild(hmm)

				game.ReplicatedStorage.StarbloxRemove:FireAllClients(col)
			end
		end
	end
end)

game.Workspace.Starblox.End1.Touched:Connect(function(hit)
	if hit.Parent.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.Parent:FindFirstChild("Humanoid") then
			game.ReplicatedStorage.StarbloxEnd:FireClient(game.Players:FindFirstChild(hit.Parent.Parent.Name))
			game.Players:FindFirstChild(hit.Parent.Parent.Name).Shift.Value = false
			script.Parent.Paycheck.Disabled = true
		else
			local hmm = hit.Parent.Parent.Name
			local col = game.Players:FindFirstChild(hmm)

			game.ReplicatedStorage.StarbloxRemove:FireAllClients(col)
		end
	end
end)

game.Workspace.Starblox.End2.Touched:Connect(function(hit)
	if hit.Parent.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.Parent:FindFirstChild("Humanoid") then
			game.ReplicatedStorage.StarbloxEnd:FireClient(game.Players:FindFirstChild(hit.Parent.Parent.Name))
			game.Players:FindFirstChild(hit.Parent.Parent.Name).Shift.Value = false
			script.Parent.Paycheck.Disabled = true
		else
			local hmm = hit.Parent.Parent.Name
			local col = game.Players:FindFirstChild(hmm)

			game.ReplicatedStorage.StarbloxRemove:FireAllClients(col)
		end
	end
end)

game.Workspace.Starblox.End3.Touched:Connect(function(hit)
	if hit.Parent.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.Parent:FindFirstChild("Humanoid") then
			game.ReplicatedStorage.StarbloxEnd:FireClient(game.Players:FindFirstChild(hit.Parent.Parent.Name))
			game.Players:FindFirstChild(hit.Parent.Parent.Name).Shift.Value = false
			script.Parent.Paycheck.Disabled = true
		else
			local hmm = hit.Parent.Parent.Name
			local col = game.Players:FindFirstChild(hmm)
			
			game.ReplicatedStorage.StarbloxRemove:FireAllClients(col)
		end
	end
end)

game.ReplicatedStorage.Paycheck.OnServerEvent:Connect(function(player)
	player.leaderstats.Cash.Value += 16
end)

And here's my local script:

game.ReplicatedStorage.StarbloxStart.OnClientEvent:Connect(function()
	script.Parent.Enabled = true
	script.Parent.Paycheck.Disabled = false
end)

game.ReplicatedStorage.StarbloxEnd.OnClientEvent:Connect(function()
	script.Parent.Enabled = false
	script.Parent.Paycheck.Disabled = true
end)

And here is the local script that sends a message to the server to pay and has the loop:

local starblox = game.Teams["Starblox Employee"]
local player = game.Players.LocalPlayer

while true do
	wait(1)
	print("second")
	player.Time.Value = player.Time.Value + 1
	if player.Time.Value == 60 then
		print("hour")
		player.Time.Value = 0
		if player.Team == starblox  then
			print("starblox")
			game.ReplicatedStorage.Paycheck:FireServer()
		end
	end
end

For some reason, right now it adds 32 to the Cash instead of 16. Why does it do this?

1 answer

the loop might run twice since you are doing wait(1), also easily exploitable I try to avoid remove events as much as I can bc of this. This sort of thing can be ran on a script in serverscriptservice

1 comment

0

So how would I fix it?

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