I just wanna wanna make a script that does what I want above when a player is on a certain part. I understand I can use the idled event, but how would I get that to only occur when a player is on a certain part.
local players = game:GetService("Players")
local touching = false
local hit = script.Parent
players.PlayerAdded:connect(function(plr)
local plrN = plr.Name
script.Parent.Touched:connect(function(p)
for i, v in pairs(players:GetPlayers()) do
if p.Name == plrN then
v.PlayerGui.AFKGui.Text:TweenPosition(UDim2.new(0.817, 0, 0.91, 0), "In", "Linear", 0.5)
touching = true
hit = p
end
end
end)
script.Parent.TouchEnded:connect(function()
for i, v in pairs(players:GetPlayers()) do
if hit.Name == plrN then
v.PlayerGui.AFKGui.Text:TweenPosition(UDim2.new(1, 0, 0.91, 0), "In", "Linear", 0.5)
touching = false
end
end
end)
plr.Idled:connect(function(time)
if hit == plr.Character and touching == true and time >= 5 then
hit.Character.HumanoidRootPart.CFrame = hit.Character.HumanoidRootPart.CFrame * CFrame.new(0, 1, 0)
end
end)
end)
