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

How to make this script run only for the local player?

I'd like to make this script run only for the local player since I don't want everyone else to hear the sound that will be played when the "Part" is removed. The thing is when I put the code in Local Script it doesn't work but when it's in Normal Script in "ServerScriptStorage" it works perfectly, please help!

The Code:

local players = game:GetService("Players") players.PlayerAdded:Connect(function(player) for i, v in pairs(workspace.Model:GetDescendants()) do if v:IsA("Part") or v:IsA("part") then v.Sound.PlayOnRemove = true end end end)

1 answer

Alright I managed to fix it by changing the script!

Script:

local players = game:GetService("Players") local sound = game.SoundService.Sound local player = players.LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local db = false

for i, v in pairs(game.Workspace.Model:GetDescendants()) do if v:IsA("Part") or v:IsA("part") then

	v.Touched:Connect(function(hit)
		if not db and char == hit.Parent  then
			db = true
			sound = v.Sound
			v.Sound.PlayOnRemove = true
			db = false
		end
	end)

end

end

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