local TouchDec = script.Parent
local ScreenText = TouchDec.Parent.SpotScreen.SurfaceGui.ScreenFrame.ScreenText
local PlayersTouching = {}
TouchDec.Touched:Connect(function(Touch)
local player = game:GetService("Players"):GetPlayerFromCharacter(Touch.Parent)
if player and not table.find(PlayersTouching, player.UserId) then
table.insert(PlayersTouching, player.UserId)
ScreenText.Text = #PlayersTouching .. "/2"
print(#PlayersTouching)
game.SoundService:PlayLocalSound(game.SoundService.SpotSound)
end
end)
TouchDec.TouchEnded:Connect(function(TouchEnd)
local player = game:GetService("Players"):GetPlayerFromCharacter(TouchEnd.Parent)
if player and table.find(PlayersTouching, player.UserId) then
table.remove(PlayersTouching, table.find(PlayersTouching, player.UserId))
ScreenText.Text = #PlayersTouching .. "/2"
print(#PlayersTouching)
end
end)
so I have this script that changes the spotscreen text depending on how many players are touching the TouchDec (Invisble Part) and I want to play a sound when a player touches the part I tried using PlayLocalSound as you see here
game.SoundService:PlayLocalSound(game.SoundService.SpotSound)
but I always get this error on the output
SoundService:PlayLocalSound only works on a client.
so basically I want to play the sound for the player who touched the TouchDec only (Locally)