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
01 | local Seat = workspace.Model.Seat |
02 | Seat.ChildAdded:Connect( function (Child) |
03 | if Child:IsA( "Weld" ) and Child.Name = = "SeatWeld" then |
04 | local Player = game.Players:GetPlayerFromCharacter(Child) |
05 | local CloneScriptChild = script.LocalScript:Clone() |
06 | CloneScriptChild.Parent = Player print ( "OK!" ) |
07 |
08 | Seat.ChildRemoved:Connect( function (Child) |
09 | CloneScriptChild:Destroy() print ( "NOOOOOOOOOOOOOOOO" ) |
10 | end ) |
11 | end |
12 | 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
01 | local Seat = workspace.Model.Seat |
02 | Seat.ChildAdded:Connect( function (Child) |
03 | if Child:IsA( "Weld" ) and Child.Name = = "SeatWeld" then |
04 | local Character = Child.Part 1. Parent |
05 | local Player = game.Players:GetPlayerFromCharacter(Character) --(child.Part1[HumanoidRootPart].Parent) |
06 | local CloneScriptChild = script.LocalScript:Clone() |
07 | CloneScriptChild.Parent = Player.Character print (Child.Part 1 ) |
08 |
09 | Seat.ChildRemoved:Connect( function (Child) |
10 | CloneScriptChild:Destroy() print ( "NOOOOOOOOOOOOOOOO" ) |
11 | end ) |
12 | end |
13 | end ) |