Touched event somehow broken?

For some reason when a player touches the part, that starts the transition for all the players in the game. I just want it to affect the player that touched it.
The script is a local script, im not that dumb :upside_down_face:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer

local soundsFolder = ReplicatedStorage.Sounds

local buttonsGui = script.Parent.Parent.Buttons
local transitionGui = script.Parent
local transitionIn = transitionGui.In
local transitionOut = transitionGui.Out

local shopTp = workspace.ScriptableObjects.ShopTp
local shopOpen = workspace.ScriptableObjects.ShopOpen

local swishSound = soundsFolder.TransitionSounds.Swish

local info = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)

local tranPosInGoTo = UDim2.new(0.5,0,1.8,0)
local tranPosIn = UDim2.new(0.5,0,-0.73,0)
local tranPosOutGoTo = UDim2.new(0.5,0,-0.8,0)
local tranPosOut = UDim2.new(0.5,0,1.73,0)

local tranInTween = TweenService:Create(transitionIn, info, {Position = tranPosInGoTo})

local debounce = false

shopTp.Touched:Connect(function(hit)
	if not debounce then
		debounce = true
		local playerCheck = Players:GetPlayerFromCharacter(hit.Parent)
		if playerCheck then
			transitionIn.Visible = true
			tranInTween:Play()
			task.wait(0.2)
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
			swishSound:Play()
			task.wait(0.3)
			playerCheck.Character:SetPrimaryPartCFrame(shopOpen.CFrame + Vector3.new(0,5,0))
			buttonsGui.Enabled = false
			task.wait(0.5)
			transitionIn.Visible = false
			transitionIn.Position = tranPosIn
			debounce = false
		end
	end
end)
1 Like

this is because the script is suspected to be a LocalScript, and it does not make sure playerCheck is the actual player (do it with player.Name) so it plays when someone enters the store for everyone

The reason why it is showing up for everyone is because you never check if the player who touched the shop is the same as the local player. To fix this, on line “if playerCheck then”, change it to “if playerCheck == player then”

i tried that but then the shop only accepts 1 player in the server and if another player enters then it just doesnt accept anyone

uh… i dont understand, can you show me an example?

Whoops you also have to move the debounce to under that if statement (so put it right under “if playerCheck == player then”)

Edit: to clarify, put the debounce = true

1 Like

omg thank you, i didnt know it was that simple :sweat_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.