I have problem with one script. It is not copying the part and I don’t know why. This script should copy part and the sound but it’s not. that script is in tool and in local script. Please help fast.
local tool = script.Parent
local background = script.Parent.Parent.Parent.Workspace.Powertest
local music = background.sound
tool.Activated:Connect(function(player)
local char = player.Character
if not char then
return
ends
local humanoid = char:WaitForChild("Humanoid")
local clonedBackground = background:Clone()
clonedBackground.Name = "testPart"
clonedBackground.Parent = script.Parent.Parent.Parent.Workspace
clonedBackground.Position = char.Position
clonedBackground.Rotation = char.HumanoidRootPart.Rotation
local clonedMusic = music:Clone()
clonedMusic.Name = "sound1"
clonedMusic.Parent = game.Workspace.Powertest
humanoid.WalkSpeed = 0
wait(5)
humanoid.WalkSpeed = 16
end)
Also, rather than looking for the workspace through the ancestry (parent.parent.parent etc) you can just use workspace. Same with workspace descendants workspace:FindFirstChild("partToLookFor")
I got error that character=nil. Should I path it like game.players.localplayer.character ?
local tool = script.Parent
local background = game.Workspace:FindFirstChild(“Powertest”)
tool.Activated:Connect(function(player)
local char = player.Character
if not char then
return – Sprawdź, czy gracz ma postać
end
local humanoid = char:WaitForChild("Humanoid")
local clonedBackground = background:Clone()
clonedBackground.Name = "testPart"
clonedBackground.Parent = game.Workspace
clonedBackground.Position = char.Position
clonedBackground.Rotation = char.HumanoidRootPart.Rotation
humanoid.WalkSpeed = 0
wait(5)
humanoid.WalkSpeed = 16
end)
Hey!
First of all. I am not sure if player is an arguement that is retrieved from that “Activated” event. If it’s not, try to reference the character by doing:
tool.Activated:Connect(function(player)
local char = tool.Parent
if not char then
return – Sprawdź, czy gracz ma postać
end
local humanoid = char:WaitForChild("Humanoid")
local clonedBackground = background:Clone()
clonedBackground.Name = "testPart"
clonedBackground.Parent = game.Workspace
clonedBackground.Position = char.PrimaryPart.Position
clonedBackground.Rotation = char.HumanoidRootPart.Rotation
humanoid.WalkSpeed = 0
wait(5)
humanoid.WalkSpeed = 16
end)
If it is an arguement, you can try this:
I noticed that in your code you are trying to access the position of a model, the model being the character.
If I am not mistaken, a model does not have a position that you can access, you have to actually specify the primary part’s position. That is if I am not mistaken.