Script is not working how it should

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)

2 Likes

“ends” looks like a typo to fix

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")

Still it’s not working

local tool = script.Parent
local background = game.Workspace:FindFirstChild("Powertest")
local music = background.MagicWinx

tool.Activated:Connect(function(player) 
	local char = player.Character
	if not char then
		return
	end

	local humanoid = char:WaitForChild("Humanoid")

	local clonedBackground = background:Clone()
	clonedBackground.Name = "testPart"
	clonedBackground.Parent = game.Workspaces
	clonedBackground.Position = char.Position
	clonedBackground.Rotation = char.HumanoidRootPart.Rotation

	local clonedMusic = music:Clone()
	clonedMusic.Name = "MagicWinx"
	clonedMusic.Parent = game.Workspace.Powertest

	humanoid.WalkSpeed = 0
	wait(5)
	humanoid.WalkSpeed = 16
end)

it’s fixed one

workspace

Do you get any errors in the output window?

Is this a local script? If it is then I highly suggest making it a server script for it to work properly

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)

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.

	local clonedBackground = background:Clone()
	clonedBackground.Name = "testPart"
	clonedBackground.Parent = script.Parent.Parent.Parent.Workspace
	clonedBackground.Position = char.PrimaryPart.Position
	clonedBackground.Rotation = char.HumanoidRootPart.Rotation

This code should probably work better. If it does not, I was wrong. I will try to help further if it ends up being wrong.

Hope this helps!

1 Like

I did it before but thanks anyways.

No worries! Good luck with your project!

Thanks!!!:sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles::sparkles:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.