Hello,
I am currently working on a Survival Game
and I'm trying to have a tool so when you click on the tool it will clone a Campfire
from ReplicatedStorage
to Workspace
and it clones. However, when it clones, the scripts inside the model do not work. (e.g a raft seat wouldn't be seatable after being cloned) I've been told that the reason for this is because the tool is using a LocalScript
to clone the Model therefore it will not work.
However, I am not sure how I would go to transfer my LocalScript
to a ServerScript
Here is the script I use (It's for a campfire where if you click on it, it brings up a GUI) (It's clickable when it's on workspace itself but not when cloned through the tool)
local ReplicatedStorage = game:GetService("ReplicatedStorage") local Player = game:GetService("Players").LocalPlayer local Campfire = ReplicatedStorage:WaitForChild("Campfire") local Cursor = Player:GetMouse() local CampfireTool = script.Parent function onActivated() local ClonedCampfire = Campfire:Clone() ClonedCampfire.Parent = workspace ClonedCampfire:MoveTo(Cursor.hit.p) CampfireTool:Destroy() end script.Parent.Activated:Connect(onActivated)
I have this script for a Raft as well but same thing happens but with a VehichleSeat
If I could get some help with this, it would be great.
Thanks!
Improvements
Use :GetService()
for the Workspace
Use Hit.Position
as hit.p
is deprecated
Explanation
You can create the campfire on the server by using a RemoteEvent
to tell the server where to place the object, the tool will work normally as it remains on the Client
The script below handles the remote creation / event for you and would preferably be placed in ServerScriptService
Server Script in ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage") local Campfire = ReplicatedStorage:WaitForChild("Campfire") local Remote = Instance.new("RemoteEvent") Remote.Name = "CampfireRemote" Remote.Parent = ReplicatedStorage Remote.OnServerEvent:Connect(function(player, position) local ClonedCampfire = Campfire:Clone() ClonedCampfire.Parent = game:GetService("Workspace") ClonedCampfire:MoveTo(position) end)
Local Script in Tool
local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remote = ReplicatedStorage:WaitForChild("CampfireRemote") local Player = game:GetService("Players").LocalPlayer local Cursor = Player:GetMouse() local CampfireTool = script.Parent CampfireTool.Activated:Connect(function(input, click) Remote:FireServer(Cursor.Hit.Position) CampfireTool:Destroy() end)