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

how to make a part that uses a touch event but effects everyone but you? (see description)

Asked by 3 years ago

So im trying to make a Flash game, he has this thing where he can go so fast that everyone around him is standing still. I want to do this and use like a Bubble and if they go inside that bubble then they move very slow. Idk if there is a way to make it so the person that made that bubble doesn't get effected by it (I use a touch event)

**this is my code for the part below **

local part = script.Parent



part.Touched:Connect(function(hit)
    local player = hit.Parent:WaitForChild("Humanoid")
    player.WalkSpeed = 1
end)


part.TouchEnded:Connect(function(hit)
    local player = hit.Parent:WaitForChild("Humanoid")
    player.WalkSpeed = 16
end)

1 answer

Log in to vote
0
Answered by
A_Mp5 222 Moderation Voter
2 years ago

from what I understand, when a player is touching a certain button, everyone else is moving slowly? Set a variable to check the person who made the bubble, then:

local part = script.Parent
local bubblemaker = nil -- set this variable when someone makes bubble, or use a different value stored somewhere else


part.Touched:Connect(function(hit)
    local player = hit.Parent:FindFirstChild("Humanoid")
if player ~= nil and hit.Parent.Name ~= bubblemaker.Name then
    player.WalkSpeed = 1
end
end)


part.TouchEnded:Connect(function(hit)
    local player = hit.Parent:FindFirstChild("Humanoid")
if player ~= nil and hit.Parent.Name ~= bubblemaker.Name then
    player.WalkSpeed = 16
end
end)

(this is untested, and you will have to edit it to make it work with your game

Ad

Answer this question