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!
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.