Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Model won't get cloned to Cursor.hit.p?

Hello,

I am currently making a survival game and I am trying to make a tool which can spawn a model upon using the tool. When I use the tool it clones the Model to workspace but it doesn't give the position of Cursor.hit.p.

I am aware that models do not have a position so how would I go to make it so the model goes to the mouse position?

I have a LocalScript Inside my Tool:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Player = game:GetService("Players").LocalPlayer
local Raft = ReplicatedStorage:WaitForChild("Raft")
local Cursor = Player:GetMouse()

function onActivated()
Raft:Clone().Parent = workspace
Raft:MoveTo(Cursor.hit.p)
end


script.Parent.Activated:connect(onActivated)

If I could get some help with this script, that would be great!

Thanks!

5 comments

0

Change line 8 to Raft:MoveTo(Cursor.Hit.p)

0

Hello, thanks for ther answer, however, that did not fix my problem. It cloned the Raft to the position I gave before putting in in Replicated Storage.

0

Is the raft welded? If so, did you specify a primary part?

0

Yes, the Raft has all parts Welded with a Weld Constraint to the Base which is the Main part or Primary Part

0

I have also noticed that upon the Raft spawning to the original coodrinations, the Vehicle Seat which you drive the raft with is non functional with the new clone

1 answer

✓ Accepted answer

i think i know whats the problem,when you are saying to the raft to move Raft:MoveTo(Cursor.hit.p) it referring to the raft in replicated storage and not to the raft you just cloned, a simple way to fix is to add a variable to what you are cloning, ex.


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Player = game:GetService("Players").LocalPlayer
local Raft = ReplicatedStorage:WaitForChild("Raft")
local Cursor = Player:GetMouse()

function onActivated()
	local ClonedRaft = Raft:Clone()
	ClonedRaft.Parent = game.workspace
	ClonedRaft:MoveTo(Cursor.hit.p)
end


script.Parent.Activated:connect(onActivated)

also you might notice that the raft is only visible to the Client but other players cant see it. this is because you are using a local script. if you want me to explain to you how you can make it visible to the server, i will.

2 comments

0

That worked! Thank you so much! Also no need, It's a single player game so I won't have other players to see it! Thansk for the answer :D

0

ok

This discussion is preserved as it was. New answers, comments, and votes are closed.