Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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

Ad

Answer this question