Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I do not understand why my local script is not working? I accept answers

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)

1 answer

✓ Accepted answer

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.

1 comment

0

Thank ya man! I still just don’t understand why the original code didn’t work since it works only on a player to player basis..

This discussion is preserved as it was. New answers, comments, and votes are closed.