I want to play a sound from a normal script but I want to appear on a client only

I want to play a sound from a normal script but I want to appear on a client only im trying to fire an event to fix it these are the scripts:

~LOCAL SCRIPT

game.ReplicatedStorage.Error.OnClientEvent:Connect(function()
script.Parent.Error:Play()
print("Fired")
end)

~NORMAL SCRIPT

game.ReplicatedStorage.Error:FireClient()

game.ReplicatedStorage.Error:FireClient([Player Instance])

You need to provide this function with a player who should receive this. Remove the square brackets

Oh ok ill try that and put this as a solution if it works thank you

what is a player instance is it like plr in brackets?

A Player Instance is simply just the Player object, or game.Players["4HM4DJ'] if that clarifies a bit more

You’d need to find some way to get the Player inside a server script, which is the thing here

You have several different Events & functions that you can use that could help you get it, but it depends on when the Event is fired

can i use when the player joins the game? i tried putting plr but it still didnt work?

It should look something like this:

game.Players.PlayerAdded:Connect(function(Player)
    wait(10)
    game.ReplicatedStorage.Error:FireClient(Player)
end)

Yeah thats what i did… this is the normal script (a part of it)

Does the LocalScript print anything when it’s fired?

Nope but i get an error " 22:31:44.898 Argument 1 missing or nil - Server -"

Try just removing the PlayerAdded event, I think it’s defined as nil due to there being 2 functions tightening it

script.Parent.MainMesh.ClickDetector.MouseClick:Connect(function(Player)
    local PlayerBasketCapacity = game.ServerStorage.Baskets.StarterBasket.MaxCapacity
    if plr.PlayerDataFolder.PlayerFoodAmount.Value >= PlayerBaskerCapacity.Value then
        print("Bucket Capacity is full!")
        plr.PlayerDataFolder.CanCollect.Value = false
        game.ReplicatedStorage.Error:FireClient(Player)
    end
end)
1 Like