How do I find the player who clicked and then wait the value of a "NumberValue" in that player?

What do you want to achieve? Keep it simple and clear!

I’m making a regen button that when you click it, it looks for a number value inside the player that clicked it and then teleports the player inside the model and waits the amount of time in that number value inside the player and then it destroys the model the player is inside of and resets their number value.

What is the issue? Include screenshots / videos if possible!

The issue is: as soon as you click the button it teleports you into the model but it instantly destroys the model instead of waiting the time in the number value of the player and THEN destroying the model.

What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have noticed that if you replace the wait with a number it waits that time and then destroys the model, almost like what I want but I want it to wait the time in the number value of the player.
I have looked all over the Dev Forum but I can’t seem to find a solution. I have also looked in the output and there doesn’t seem to be any error regarding this particular script.

Code:

local modelname = "BathBoat" 
------------------------------------------------------------------------------------


local modelbackup = script.Parent.Parent:FindFirstChild(modelname):clone()
local trigger = script.Parent

enabled = true

script.Parent.ClickDetector.MouseClick:Connect(function(player)
local time1 = player:WaitForChild("BoatTime").Value
	if enabled == true then

		enabled = false
		trigger.BrickColor = BrickColor.new("Crimson")

	if script.Parent.Parent:FindFirstChild(modelname) ~= nil then

		script.Parent.Parent:FindFirstChild(modelname):Destroy()

	end

		local modelclone = modelbackup:clone()
		modelclone.Parent = script.Parent.Parent
		modelclone:MakeJoints()
		player.Character.HumanoidRootPart.CFrame = CFrame.new(script.Parent.Parent.BathBoat.Drive.Position + Vector3.new(0,0,0))
		
		local time1 = player:WaitForChild("BoatTime").Value
	    wait(time1)
        script.Parent.Parent:FindFirstChild(modelname):Destroy()
		enabled = true
		trigger.BrickColor = BrickColor.new("Lime green")
		end

end)

I hope a solution is found. Thanks!

Have you tried to debug by printing the value before you wait? It sounds like the “BoatTime” value isn’t being set in the first place.

2 Likes

Hmmm. It says 0. I am confused as to why it thinks the value is 0 then because when I look into my player and see the value it says 15.

Try deselecting and reselecting it, sometimes the values don’t update when you’re viewing it’s value. Something may be setting the value to 0?

Your changing it from the client. Respect FilteringEnabled. Changes on the client don’t appear on the server.

So how would I change it on the server?

RemoteEvents. Thirtycharacters

2 Likes

You would need to use RemoteEvents to tell the server you want to change the value. Things like this should be handled on the server, and you should look into making secure code with remote events if you haven’t already.

3 Likes