'Start roblox script with RemoteEvent

How i can do something like that and fix this (i learn script)

local Event = game.ReplicatedStorage.SoundPlayEventWirlord

Event.OnServerEvent:Connect(function(plr, NameId)
    local theplayer = plr
    print(NameId)
    if NameId == "one" then
        game.Workspace[theplayer].one:Play()
        if NameId == "two" then
            print("IT IS TWO ?!")
        end
    end
end)


Solution 1:[1]

Based on the comments, your question seems to be how to properly find the player's character model in the workspace.

You can do this two ways. You can use the player's name to index into the Workspace :

game.Workspace[plr.Name].one:Play()

or, you can simply use the Character property of the player :

plr.Character.one:Play()

You should be careful though, as the Character model isn't guaranteed to exist in the workspace. So you should put safety checks in place :

if plr.Character and plr.Character.Parent ~= nil then
    plr.Character.one:Play()
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kylaaa