Alright, there are a few errors in this script, so let's just go through them one by one.
local hitTarget = game.Players.LocalPlayer:GetMouse().Hit
This line is completely useless, let's just get rid of it.
function cloneWood()
local cloneTemp = game.Workspace.WoodBlock1
local clonedWood = cloneTemp:Clone()
clonedWood.Position = Vector3.new(hitTarget)
end
local tool = script.Parent
tool.Equipped:connect(function(Mouse)
Mouse.Button1Down:connect(function()
local hitTarget = game.Players.LocalPlayer:GetMouse().Hit
cloneWood()
end)
end)
But, oh no! Now hitTarget isn't defined for the function, and so it will be nil. However, there is a way around this, an arguement!
function cloneWood(hitTarget)
local cloneTemp = game.Workspace.WoodBlock1
local clonedWood = cloneTemp:Clone()
clonedWood.Position = Vector3.new(hitTarget)
end
Now that's good and all, but you never parent clonedWood so let's parent that at then end of function.
function cloneWood(hitTarget)
local cloneTemp = game.Workspace.WoodBlock1
local clonedWood = cloneTemp:Clone()
clonedWood.Position = hitTarget
clonedWood.Parent = game.Workspace
end
Alright, this is great. We have a nice little function defined, and we're ready to use it!
But first, let's take a look at the second half of your script.
local tool = script.Parent
tool.Equipped:connect(function(Mouse)
Mouse.Button1Down:connect(function()
local hitTarget = game.Players.LocalPlayer:GetMouse().Hit
cloneWood()
end)
end)
I'm not sure why you do line 4 there, you already have the mouse thanks to the first line, let's just clean that up a bit.
local tool = script.Parent
tool.Equipped:connect(function(Mouse)
Mouse.Button1Down:connect(function()
local hitTarget = Mouse.Hit
cloneWood(hitTarget)
end)
end)
And as a final note,mouse.Hit returns a CFrame value, so you could either send over mouse.Hit.p to get the Vector3, or set the CFrame of your cloned part instead, your choice.
function cloneWood(hitTarget)
local cloneTemp = game.Workspace.WoodBlock1
local clonedWood = cloneTemp:Clone()
clonedWood.Position = hitTarget
clonedWood.Parent = game.Workspace
end
local tool = script.Parent
tool.Equipped:connect(function(Mouse)
Mouse.Button1Down:connect(function()
local hitTarget = Mouse.Hit
cloneWood(hitTarget)
end)
end)
6 comments
Where is the script?
It's on there.. I put the Lua symbol and the code in the lines..
lol I meant in the game, due to line 8 I assume it's in a tool.
just to say i feel like you are trying to make a fortnite in roblox e-e
No, not fortnite haha
I tested my finished script (with mouse.Hit.p) and it worked fine.