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

How can a LocalScript be transferred to a ServerScript?

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!

2 comments

0

Can't you just copy the script and paste it into a script?

0

I have tried that, however it did not work

2 answers

✓ Accepted answer

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)

1 comment

1

This worked! Thank you so much! I think I get a better understanding on how it works now

5 comments

0

I just realized it is blocked for some people. Just search up "How do I turn on filtering enabled without it breaking my game" And you should be good.

0

Okay I'll try that

0

I see how it's FE, however the question I was trying to ask is how to actually change the localscript to a serverscript

0

There are links in the comments of that post that are useful. Especially the comment chosen as the answer.

0

I see that what I would need to use is a RemoveEvent, however I'm not necessarily sure how to apply that to my script as the posts are rather confusing

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