This script constantly check if the player’s torso it touching a part called lobbyPart making “Act” true or false based on if the player is touching the part or not.
Problem: Nothing is printing or working. There are not errors either.
Is there a better way to do this and if not how do I fix this
--==============================================================================
--LOCAL SCRIPT >> SCRIPTS
--==============================================================================
--<<VERIABLES>>
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:WaitForChild("HumanoidRootPart")
local lobbyPart = workspace.Map.Spawn.Spawn.Base:WaitForChild("LobbyPart")
local button = script.Parent.Parent.Buttons
--==============================================================================
--<<FUNCTIONS>>
while wait(1) do
local partsTouched = torso:GetTouchingParts()
for _, part in pairs(partsTouched) do
if part == lobbyPart then
print("Player's torso is touching lobbyPart!")
button:WaitForChild("Act").Value = false
else
button:WaitForChild("Act").Value = true
end
end
end
--==============================================================================
Thanks, but it still does not work or print anything
--==============================================================================
-- LOCAL SCRIPT >> SCRIPTS
--==============================================================================
-- <<VARIABLES>>
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:WaitForChild("HumanoidRootPart")
local lobbyPart = workspace.Map.Spawn.Spawn.Base:WaitForChild("LobbyPart")
local button = script.Parent.Parent.Buttons
local debounce = false -- Used to prevent rapid firing of the event
--==============================================================================
-- <<FUNCTIONS>>
torso.Touched:Connect(function(hit)
if hit:IsA("BasePart") and hit:IsDescendantOf(lobbyPart) then
print("Player's torso is touching lobbyPart!")
if not debounce then
debounce = true
button:WaitForChild("Act").Value = false
wait(1)
debounce = false
end
else
button:WaitForChild("Act").Value = true
end
end)
--==============================================================================
Thats because your checking for the wrong thing to be touched here is the corrected code.
----==============================================================================
-- LOCAL SCRIPT >> SCRIPTS
--==============================================================================
-- <<VARIABLES>>
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:WaitForChild("HumanoidRootPart")
local lobbyPart = workspace.Map.Spawn.Spawn.Base:WaitForChild("LobbyPart")
local button = script.Parent.Parent.Buttons
local debounce = false -- Used to prevent rapid firing of the event
--==============================================================================
-- <<FUNCTIONS>>
lobbyPart.Touched:Connect(function(hit)
if hit:IsA("BasePart") and hit:IsDescendantOf(lobbyPart) then
print("Player's torso is touching lobbyPart!")
if not debounce then
debounce = true
button:WaitForChild("Act").Value = false
wait(1)
debounce = false
end
else
button:WaitForChild("Act").Value = true
end
end)
--==============================================================================
Tip
.Touched Events are replicated to the storage so everyone will see what happens!