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

How do you make it so other players can see your pet?

Asked by 4 years ago

Hello,

I'm new at scripting and I'm trying to make a pet GUI for my game. I've got the pet to show up and follow you around with a BodyGyro and a BodyPosition along with LocalScripts I am aware that LocalScripts are only visible to the player and not others. So I'm wondering, how would I go to make this visible to other players?

Screen Gui Script (Button)

local Pet = game.ReplicatedFirst.Part:Clone()
local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    Player.Parent = Player.Character
end)

Pet Script:

local Head = script.Parent.Parent:FindFirstChild("Head")
local Pet = script.Parent

while true do
    wait()
    local Pos = Head.CFrame * Vector3.new(2,2,2)
    Head.BodyGyro.CFrame = Head.CFrame
    Head.BodyPosition.Position = Vector3.new(Pos.x, Pos.y, Pos.z)
end

If I could get some help on this it would be great.

Thanks!

0
just a pro tip, instead of doing while true do wait(), you can just do while wait() do zadobyte 692 — 4y
0
Okay, thanks! RazzyPlayz 497 — 4y

1 answer

Log in to vote
3
Answered by 4 years ago

I'm still relatively new to Lua and Roblox Studio as well, so keep in mind that my answer may be inaccurate. The way I understand it, local scrips need to interact with the server using either a remote event or a remote function. You need to:

Create a remote event in your Replicated Storage (I guess you can put it anywhere, but this seems to be the convention)

Get the remote event in your local script using local remoteEvent = ReplicatedStorage:WaitForChild("NameOfRemoteEvent")

use RemoteEvent:FireServer() in your local script when the player does the action that should spawn the pet

Create a regular script, once again getting the remote event and connecting RemoteEvent:OnServerEvent with a function that makes the pet visible in the workspace. You probably want to move the line of code where you clone the pet from your local script over to the server script, and then have the pet movement code be in there as well.

0
great answer.. User#23252 26 — 4y
Ad

Answer this question