Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can a LocalScript be transferred to a ServerScript?

Asked by 4 years ago
Edited 4 years ago

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!

0
Can't you just copy the script and paste it into a script? AlphaY7 -3 — 4y
0
I have tried that, however it did not work RazzyPlayz 497 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

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
This worked! Thank you so much! I think I get a better understanding on how it works now RazzyPlayz 497 — 4y
Ad
Log in to vote
0
Answered by
AlphaY7 -3
4 years ago
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. AlphaY7 -3 — 4y
0
Okay I'll try that RazzyPlayz 497 — 4y
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 RazzyPlayz 497 — 4y
0
There are links in the comments of that post that are useful. Especially the comment chosen as the answer. AlphaY7 -3 — 4y
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 RazzyPlayz 497 — 4y

Answer this question