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

How can I make these scripts 'connect' or 'work' or something?

So, I am trying to make it so when you click on a part, you must wait a number which is an intvalue which is a child of boolvalue which is a child of a player in order to click it again. When you click another part, that value is supposed to go down, so can click faster. This is the script that I used in the part that you click again and again.

game.Players.PlayerAdded:Connect(function(plr)
local buttonbutton = 5
local buttonLvlTrack = Instance.new("BoolValue", plr)
buttonLvlTrack.Name = "ButtonLvl"
buttonLvlTrack.Value = buttonbutton
local buttonlvl = Instance.new("IntValue",buttonLvlTrack)
buttonlvl.Name = "level"
buttonlvl.Value = buttonbutton 

end)

And this is the script that I used in the thing that's supposed to reduce the time you are supposed to wait.

    local buy = script.Parent
local clickDetector = script.Parent:WaitForChild("ClickDetector")


clickDetector.MouseClick:Connect(function(plr)
	local bt = plr:WaitForChild("ButtonLvl"):FindFirstChild("level").Value
	bt = bt - 1

end)

There are no errors, warnings, or anything, but still won't work. Please help ^^

1 comment

0

In the last snippet you are using values and not references.

1 answer

✓ Accepted answer

General Issues

Use :GetService() to retrieve the Players Service

Define the Parent of each Instance outside of the Instance.new() function

Issues

You are defining bt as a reference value, so when you write bt = bt - 1 you are not changing the actual value, you are merely writing that the local variable bt is now 1 less than it was before. Instead, you can make bt be the level instance, and then for the math, state the Value Property directly in order to change it.

Revised Server Script

game:GetService("Players").PlayerAdded:Connect(function(plr)
	local buttonbutton = 5
	local buttonLvlTrack = Instance.new("BoolValue")
	buttonLvlTrack.Name = "ButtonLvl"
	buttonLvlTrack.Value = buttonbutton
	buttonLvlTrack.Parent = plr
	
	local buttonlvl = Instance.new("IntValue")
	buttonlvl.Name = "level"
	buttonlvl.Value = buttonbutton
	buttonlvl.Parent = buttonLvlTrack
end)

local buy = script.Parent
local clickDetector = buy:WaitForChild("ClickDetector")

clickDetector.MouseClick:Connect(function(plr)
    local bt = plr:WaitForChild("ButtonLvl"):FindFirstChild("level")
    bt.Value = bt.Value - 1
end)

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