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

How can I turn this Local Script into a Server Script?

Asked by 3 years ago

Hello there, I'm trying to make a system in which when you join the game the server will clone a specific part and through a local script I made it so that part's position is updated so it is always beside you. The problem is that since it is a local script it only shows that part following me for myself, others can't see it and it wasn't supposed to be like that. How can I turn this local script into a server script and keep it working as it is considering I can't get LocalPlayer through a server script? (If I remember correctly)

SERVER SCRIPT

local Players = game:GetService("Players")

local PetStorage = workspace.PetStorage
local PetWorkspace = workspace.PetWorkspace

Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        local PlayerPet = PetStorage.Fire:Clone()
        PlayerPet.Name = "Fire"
        PlayerPet.Parent = PetWorkspace
    end)    
end)

LOCAL SCRIPT

local Player = game:GetService("Players").LocalPlayer
local RunService = game:GetService("RunService")

local PetStorage = workspace.PetStorage
local PetWorkspace = workspace.PetWorkspace

local function Render()
    PetWorkspace.Fire.CFrame = Player.Character.HumanoidRootPart.CFrame * CFrame.new(1.5, 1.5, -0.5)
end

RunService:BindToRenderStep("RenderPet", 1, Render)

Answer this question