basically im trying to parent this clone of a localscript that is parented to a script in serverscriptservice to the player's character
but when i play the game the localscript wasnt there in the character model but the output printed ok which means it did work so i dont know where it went
local Seat = workspace.Model.Seat Seat.ChildAdded:Connect(function(Child) if Child:IsA("Weld") and Child.Name == "SeatWeld" then local Player = game.Players:GetPlayerFromCharacter(Child) local CloneScriptChild = script.LocalScript:Clone() CloneScriptChild.Parent = Player print("OK!") Seat.ChildRemoved:Connect(function(Child) CloneScriptChild:Destroy() print("NOOOOOOOOOOOOOOOO") end) end end)
i dont know if im just being stupid or not
as in my comment, welds are parented to the seat, not player objects themselves, you have a check for if it's a weld, but then immediately try to do game.Players:GetPlayerFromCharacter(Child)
, but since Child
is a weld, Player
then becomes nil since it couldnt find a player, and in the following statement CloneScriptChild.Parent = Player
you just parent the script to nil, effectively removing it.
you could instead,
- look at the parents of
Part0
andPart1
of the weld and get the player throughGetPlayerFromCharacter
that way:Connect
toSeat:GetPropertyChangedSignal("Occupant")
, since the seat'sOccupant
property is set to the humanoid of the player currently sitting in it, retrieving the player object is then trivial
fixed it
local Seat = workspace.Model.Seat Seat.ChildAdded:Connect(function(Child) if Child:IsA("Weld") and Child.Name == "SeatWeld" then local Character = Child.Part1.Parent local Player = game.Players:GetPlayerFromCharacter(Character)--(child.Part1[HumanoidRootPart].Parent) local CloneScriptChild = script.LocalScript:Clone() CloneScriptChild.Parent = Player.Character print(Child.Part1) Seat.ChildRemoved:Connect(function(Child) CloneScriptChild:Destroy() print("NOOOOOOOOOOOOOOOO") end) end end)