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

How do I make it so that a certain part of a script only starts when touching a certain part?

I'm making a game with a script THAT CHANGES THE PLAYERS SCORE EVERY SECOND, AND RESETS BACK TO ZERO WHEN THE PLAYER DIES. This works fine. However, I need the timer to only start when the player isn't touching a certain part (Called "StartPart"). I still need to keep the same aspects of the script I meantioned above (In CAPITALS). Sorry if the script is a bit confusing. Here's the script I have currently:

local Players = game:GetService("Players")
	local UpdatePoints = false
	 
	Players.PlayerAdded:Connect(function(Player)   
		    Player.CharacterAdded:Connect(function(Character)
			        UpdatePoints = true
			 
			        local Leaderstats = Instance.new("Folder")
			        Leaderstats.Name = "leaderstats"
			        Leaderstats.Parent = Player
			 
			        local Points = Instance.new("IntValue")
			        Points.Name = "Points"
			        Points.Parent = Leaderstats
			 
			        Player.leaderstats.Points.Value = 0
			 
			        local Humanoid = Character.Humanoid
		        Humanoid.Died:Connect(function()
				            UpdatePoints = false
				            Player.leaderstats.Points.Value = 0
			        end)
			 
			        while (UpdatePoints) do
				            wait(1)
			            Player.leaderstats.Points.Value += 1
				            if not (UpdatePoints) then
					                break
				            end
				        end
			    end)
end)

1 answer

Use a if then event to detect if the player is touching the part, if they are, break the script

I dont really know how to execute this but ill try

local function onTouch(part)
	return end
end
part.Touched:Connect(onTouch)

it probably doesnt work so here are the dev forum links

https://devforum.roblox.com/t/can-someone-explain-returning-to-me-like-im-3/206702/2 returning ^

https://developer.roblox.com/en-us/api-reference/event/BasePart/Touched

Touched event ^

3 comments

0

could you actually write the script?

0

ill try to do research on the dev forum i know the actually idea just needa know how to execute it, just wait

0

k...

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