Script doesnt work, but theres no error 5

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A throwable snowball object that when you click anywhere with it, a clown is thrown.
  2. What is the issue? Include screenshots / videos if possible!
    Whats on the title, it just does not work.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Print() to check where its not working, changing values, etc. Yes.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
game:GetService("ReplicatedStorage").Throw.OnServerEvent:Connect(function(player)
	local clone=script.Parent:Clone()
	clone.Parent=game.Workspace
	clone.Position=script.Parent.Position
	clone.Rotation=script.Parent.Rotation
	local bv=Instance.new("BodyVelocity")
	bv.Parent=clone
	bv.Velocity=player.Character.HumanoidRootPart.CFrame.LookVector
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

I really need more context here. I have a feeling the script isn’t working because it’s not placed in the correct service. Could you send us a screenshot of your Explorer?

Also, this line:

local clone=script.Parent:Clone()

You’re cloning the parent of the script, and you parent it to the workspace, so that will lead to an infinite loop, if you aren’t aware. Assuming this is the only code in the script.

Another thing,

clone.Rotation=script.Parent.Rotation

This will not work. .Rotation. is read only, you can’t modify it. Try using CFrame instead.

And you also should not use BodyVelocity, as it is deprecated. Use LinearVelocity instead.

And on top of all that, you may need to increase the velocity of this line:

bv.Velocity=player.Character.HumanoidRootPart.CFrame.LookVector

.LookVector is a unit vector, which means it has a magnitude of 1. That’s really slow for a projectile.

2 Likes

Here.

1 Like

Have the place file if you need more details.
builders2.rbxl (109.9 KB)

1 Like

Instead of saying script.Parent:Clone(), parent the script to the tool itself, and then do script.Parent.Handle:Clone().

And then do everything else I told you of.

game:GetService("ReplicatedStorage").Throw.OnServerEvent:Connect(function(player)
	local clone=script.Parent.Handle:Clone()
	clone.Parent=game.Workspace
	clone.CFrame = script.Parent.Handle.CFrame
	clone:ApplyImpulse(player.Character.HumanoidRootPart.CFrame.LookVector * 20)
end)

I also noticed you weren’t attaching the BodyVelocity to anything, it wasn’t moving.

1 Like

Still does not seem to work. I put in the new code, moved the script and its just not working at all.

1 Like

Add a print statement, tell me if the event is firing at all.

1 Like

This is the LocalScript that fires it.

local m=game.Players.LocalPlayer:GetMouse()
m.Button1Down:Connect(function()
	local t=script.Parent.Parent
	local tt=m.Target
	if tt and game.Players:GetPlayerFromCharacter(tt.Parent) and t.Equipped then
		game:GetService("ReplicatedStorage").Throw:FireServer()
	end
end)

You don’t need to do this, just use Tool.Activated. You can do it on the server.

script.Parent.Activated:Connect(function()
	local clone=script.Parent.Handle:Clone()
	clone.Parent=game.Workspace
	clone.CFrame = script.Parent.Handle.CFrame
	clone:ApplyImpulse(player.Character.HumanoidRootPart.CFrame.LookVector * 20)
end)

It works a tiny bit, but theres a new error. Players.T0I_C.Backpack.Snow-covered Rock.Script:5: attempt to index nil with ‘Character’

My apologies, I forgot this was a server script.

script.Parent.Activated:Connect(function()
    local lookVector = script.Parent.HumanoidRootPart.CFrame.LookVector 
	local clone=script.Parent.Handle:Clone()
	clone.Parent=game.Workspace
	clone.CFrame = script.Parent.Handle.CFrame
	clone:ApplyImpulse(lookVector * 20)
end)

Try this.

Other error. HumanoidRootPart is not a valid member of Tool “Workspace.T0I_C.Snow-covered Rock”

1 Like

Did you place the script under the tool or the handle? Place it under the tool.

1 Like

Under the tool. I placed it under the tool.

1 Like
script.Parent.Activated:Connect(function()
    local lookVector = script.Parent.Parent.HumanoidRootPart.CFrame.LookVector 
	local clone=script.Parent.Handle:Clone()
	clone.Parent=game.Workspace
	clone.CFrame = script.Parent.Handle.CFrame
	clone:ApplyImpulse(lookVector * 20)
end)

Try this

1 Like

Its almost working but its going down, noclipping through the ground and just very slow.

1 Like

You need to set .CanCollide, true, and increase the velocity, if you want it to go up, use this expression:

clone:ApplyImpulse((lookVector + Vector3.yAxis) * 20)
1 Like

Oh yeah also, the lookvector isnt working, its going in one direction.

1 Like

Also theres no yAxis variable in the script.

1 Like

yAxis is a property of Vector3, which is a global, it doesn’t need to be defined.

1 Like