Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a script that activates while the player is touching it?

Asked by 3 years ago

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.

0
part.TouchEnded Speedmask 661 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
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

0
The problem is that when the player stops touching it should revert. RedSoloYT 10 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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.

Answer this question