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 a script that activates while the player is touching it?

I have made a script, which I thought would work but it doesn't.

while script.Parent.Touched do
	workspace.TimeSwap.Dark.Color = Color3.fromRGB(255, 0, 0)
	workspace.TimeSwap.DarkVal.Value = true	
end

When the player touches the block, another block changes color and a value becomes true, but I don't want them to stay like that I just want them to work while the player is touching it.

1 comment

0

part.TouchEnded

2 answers

script.Parent.Touched:Connect(function(hit)
    workspace.TimeSwap.Dark.Color = Color3.fromRGB(255, 0, 0)
    workspace.TimeSwap.DarkVal.Value = true 
end)

Touched is an event. That's how you handle events

1 comment

0

The problem is that when the player stops touching it should revert.

You can use TouchEnded to detect when a touch on a part stops and set the properties back to what they were before. There are examples of detecting Touched and TouchEnded events on the API reference that I have linked.

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