So for the past few days while scripting, I noticed that when I try to Clone()
an object and parent it to a character using a script in StarterCharacterScripts, the script is unable to parent the object to the character. Is StarterCharacterScripts unable to parent objects to characters, or am i just doing it wrong?
Here is the script I am using, if necessary:
-- This is a tagging script btw, it handles the tagging interaction between players because it is a hot potato-like game
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local player = game.Players:GetPlayerFromCharacter(char)
local taggedValue = player:WaitForChild("Tagged")
local holdAnim = script.HoldAnim
local holdAnimTrack = animator:LoadAnimation(holdAnim)
local debounce = false -- A cooldown between touching players, you don't want them to pass the bomb immediately...
local head = char:WaitForChild("Head")
local torso = char:WaitForChild("Torso")
local leftarm = char:WaitForChild("Left Arm")
local rightarm = char:WaitForChild("Right Arm")
local leftleg = char:WaitForChild("Left Leg")
local rightleg = char:WaitForChild("Right Leg")
local function passBomb(partTouched)
local enemyChar = partTouched.Parent
local enemyHumanoid = partTouched.Parent:FindFirstChild("Humanoid")
if enemyHumanoid ~= humanoid and debounce == false then
debounce = true -- Cooldown activate
if taggedValue.Value == true then -- If you're tagged, you get untagged
taggedValue.Value = false
holdAnimTrack:Play()
bomb = game.ReplicatedStorage.Objects.Bomb:Clone()
bomb.Parent = char -- This is the code that parents the bomb to the character, for some reason the bomb doesn't appear!
local bombAttachment = bomb.Attachment
local armAttachment = char["Right Arm"].RightGripAttachment
local weld = Instance.new("Weld", bomb)
weld.Part0 = bomb
weld.Part1 = char["Right Arm"]
weld.C0 = bombAttachment.CFrame
weld.C1 = armAttachment.CFrame
else -- If you're not tagged, you get tagged
taggedValue.Value = true
holdAnimTrack:Stop()
if bomb then
bomb.Transparency = 1
wait(1)
bomb:Destroy()
end
end
wait(1) -- How long cooldown is, or how long the player is immune to the other player's touch
debounce = false
end
end
head.Touched:Connect(passBomb)
torso.Touched:Connect(passBomb)
leftarm.Touched:Connect(passBomb)
rightarm.Touched:Connect(passBomb)
leftleg.Touched:Connect(passBomb)
rightleg.Touched:Connect(passBomb)
There may be some inaccurate and illogical things here and there in the script; it is still in progress.
Thanks for reading this post by the way, I know it is pretty long.