My local script is in StarterPlayerScript and its enabled but when a player steps on Part both player1 and player2's partSelect Variables go up. I only want the player's Variable who steps on the part to go up. I don't believe there is anything wrong with my code but who knows. Any help would be greatly appreciated.
local object = workspace.Part local debounce = false local partSelect = 0 local function test(hit) if hit.Parent:FindFirstChild("Humanoid")then if debounce == false then debounce = true local player = hit.Parent if partSelect <= 3 then partSelect = partSelect + 1 end if partSelect == 4 then partSelect = 1 end local part = game.Workspace:FindFirstChild("Part" .. partSelect) player.HumanoidRootPart.CFrame = CFrame.new(part.Position) wait(1) debounce = false end end end object.Touched:Connect(test)
Because when anyone touches the part the changes will apply, you have no filter to prevent other gamers from touching your part, you fix that by adding one, all you have to do is get the LocalPlayer and his character, then just check if hit is him.
local object = workspace.Part local debounce = false local partSelect = 0 local LocalGamer = game:GetService('Players').LocalPlayer local function test(hit) local Character = hit.Parent if Character:FindFirstChild("Humanoid") and (Character == LocalGamer.Character) then if debounce == false then debounce = true ...
and statement does what it sounds like, if this
and that is not false and not nil then continue.