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

Why is the script killing me when I try to weld it up?

Asked by 8 years ago

local lplayer = game.Players.LocalPlayer local HumT = lplayer.Character.Torso local RepStore = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") function OnPlayerAdded(plr) print("Hello!") local part2 = RepStore.Blocky:Clone() local weld = Instance.new("Weld") weld.Part0 = part2 HumT.Parent = lplayer part2.Parent = HumT weld.Part1 = HumT weld.C0 = CFrame.new(0,0,0) weld.C1 = CFrame.new(0,0,0) end for _,v in pairs(Players:GetPlayers()) do OnPlayerAdded(plr) end

It kills me when I try to weld a part to the Character's Torso. Each time I respawn.

0
I have on ReplicatedStorage a 2x2x2 part named "Blocky" as you might see. I'm trying to clone it and weld it to the Character's Torso. But for some strange reason when I press "play" the character spawns and it instantly dies, and it doesn't stop loop killing me, any help on this ? iDarkGames 483 — 8y

1 answer

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

You set the player's torso to the player, which is why it kept killing them. The torso doesn't need to be parented. You also forgot to set the parent of the weld.

And I'm not sure why it even worked, because in lines 31-33, you used 'plr' which wasn't defined. If you're trying to loop through the players and do it for all of them, then substitute plr with v, as I did. You should also connect the function to the actual player added event, which I assume is what you wanted to do from 'OnPlayerAdded', as right now it'll only run once.

local lplayer = game.Players.LocalPlayer

local HumT = lplayer.Character.Torso

local RepStore = game:GetService("ReplicatedStorage")


local Players = game:GetService("Players")

function OnPlayerAdded(plr)
    print("Hello!")

local part2 = RepStore.Blocky:Clone()
part2.Parent = game.Workspace



local weld = Instance.new("Weld")
weld.Parent = part2
weld.Part0 = part2
part2.Parent = HumT
weld.Part1 = HumT


weld.C0 = CFrame.new(0,0,0)
weld.C1 = CFrame.new(0,0,0)


end


for _,v in pairs(Players:GetPlayers()) do
    OnPlayerAdded(v)
end

game.Players.PlayerAdded:connect(OnPlayerAdded) -- Add this if you want it to run the function when a player is added.
0
It shows up with this error: "Workspace.Blocky to Workspace.Blocky.Torso would result in circular reference " iDarkGames 483 — 8y
0
I made about a billion mistakes, pretty sure I just fixed it again. My fault! Pyrondon 2089 — 8y
0
Thanks Pyrondon. Very helpfull! iDarkGames 483 — 8y
0
No problem. Pyrondon 2089 — 8y
Ad

Answer this question