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

I have been trying to figure this out for a solid hour... How to fix this?

I have been trying to make an obby and, i have been trying to make a script so each time a player touches the checkpoint it raises the stagevalue and each time the stagevalue is increased it will spawn it to that checkpoint. So if stagevalue is 1 then the player spawns at the first level checkpoint.

And here is my script:

stagevalue = 0

workspace.Stages.Stage1.Touched:Connect(function()

	stagevalue = stagevalue + 1 

end)

if stagevalue == 1 then

print("it works")

end

I touch the first checkpoint so that it prints out "it works". But nothing... This is not the whole script, this is the place of the script where the problem is located.

In my workspace i have a folder called Stages and in it a folder called Stage1 that contains the checkpoint part.

4 comments

0

can you use the ~~~~~~~~~~~~ for the script and not the print? I don't understand the script at all, it's messed

0

the print is just used so i can verify if the script works. If it prints then it works, if not then it does not work.

0
  • I edited my answer
0

LikeToScript, the script contains no errors but when i spawn it prints out "It works" but i still have not touched the first checkpoint.

3 answers

✓ Accepted answer

The problem is that when your character touches it, multiple parts touch it, so the value would be greater than 1. Try using a debounce.

local StageValue = 0
workspace.Stages.Stage1.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") and not debounce then
		debounce = false
		StageValue = StageValue + 1

		if StageValue == 1 then
			print("it works")
		end
		wait(2)
		debounce = true
	end
end)

Also, you didn't check if the part the "Stage1" touched was a player.

Hi, it doesn't print out "It works" because, it only checks it once the player joins, add the check part inside of your .Touched function, which will make it work.


local StageValue = 0;

workspace.Stages.Stage1.Touched:Connect(function(Object)
	StageValue = StageValue + 1
	if StageValue == 1 then
		print("it works")
	end
end)

2 comments

0

Thanks i will try that out.

0

I am new to scripting. What do you mean by adding an check part?

Try This

local stagevalue = -- put it here
local db = true
script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db == true then
			db = false
			
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			stagevalue = stagevalue + 1
			
			
			
		end
	end	
end)

3 comments

0

This just gives me this error: Touched is not a valid member of Workspace

0

script.Parent.Touched:Connect(function(hit) Capital C, also next time on your title describe the problem pls

0

I will try this out.

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