local Equip = script.Parent
local InvHandler = game.Players.LocalPlayer.PlayerGui.InventoryHandler
local UpperInv = InvHandler.UpperInv
local MaxPetLimit = UpperInv.MaxPetLimit
local PetLimitText = MaxPetLimit.PetLimitText
local PetPreview = UpperInv.PetPreview
local PetPreviewFrame = PetPreview.PetPreviewFrame
local Im = PetPreviewFrame.PetPreviewImage
-- We just defined all the UI elements
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BasicEggPetFolder = ReplicatedStorage.BasicEggPetFolder
local Cat = BasicEggPetFolder.Cat
local Dog = BasicEggPetFolder.Dog
local Mouse = BasicEggPetFolder.Mouse
local Dragon = BasicEggPetFolder.Dragon
local GrassyCat = BasicEggPetFolder.GrassyCat
local TeaMonster = BasicEggPetFolder.TeaMonster
-- Pet Vars
local plr = game.Players.LocalPlayer
local char = plr.Character
local debounce = false
Equip.MouseButton1Click:Connect(function()
if debounce then return end
debounce = true
if Im.Image =="rbxassetid://7620353586" then -- check if the pet you click is a cat
local Clo1 = Cat:Clone() -- Clone the cat model
local StatsValue = Instance.new("StringValue") -- adding a string value inside the model cat to see if it s equipped or not
StatsValue.Parent = Clo1
StatsValue.Value = "Equipped"
Clo1.Parent = char
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")
EquipPet:FireServer(Clo1)-- Equip pet is the Remote event
end
debounce = false
end
end)
ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")
local char = game.Workspace:WaitForChild("Character")
local humRoot = char:FindFirstChild("HumanoidRootPart")
EquipPet.OnServerEvent:Connect(function(player, Clo1)
Clo1:SetPrimaryPartCFrame(humRoot.CFrame) -- I am trying to position the pet near the player
print("Worked")
end)
I am trying to position the model cat near the player whenever the player clicks the EquipButton on the InventoryGui. So there is no errors it just the I donât think the server event is working because the Worked print will not print and the pet will not positon and When I click the Equip Button I want the cat to only Clone once but it clones serval times
I am definitely sure it is the variable you are trying to pass through the Remote.
In this attempt, I am sending the name of the âthingâ.
local Equip = script.Parent
local InvHandler = game.Players.LocalPlayer.PlayerGui.InventoryHandler
local UpperInv = InvHandler.UpperInv
local MaxPetLimit = UpperInv.MaxPetLimit
local PetLimitText = MaxPetLimit.PetLimitText
local PetPreview = UpperInv.PetPreview
local PetPreviewFrame = PetPreview.PetPreviewFrame
local Im = PetPreviewFrame.PetPreviewImage
-- We just defined all the UI elements
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BasicEggPetFolder = ReplicatedStorage.BasicEggPetFolder
local Cat = BasicEggPetFolder.Cat
local Dog = BasicEggPetFolder.Dog
local Mouse = BasicEggPetFolder.Mouse
local Dragon = BasicEggPetFolder.Dragon
local GrassyCat = BasicEggPetFolder.GrassyCat
local TeaMonster = BasicEggPetFolder.TeaMonster
-- Pet Vars
local plr = game.Players.LocalPlayer
local char = plr.Character
local debounce = false
Equip.MouseButton1Click:Connect(function()
if debounce then return end
debounce = true
if Im.Image =="rbxassetid://7620353586" then -- check if the pet you click is a cat
local Clo1 = Cat:Clone() -- Clone the cat model
local StatsValue = Instance.new("StringValue") -- adding a string value inside the model cat to see if it s equipped or not
StatsValue.Parent = Clo1
StatsValue.Value = "Equipped"
Clo1.Parent = char
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")
EquipPet:FireServer(Clo1.Name)-- Equip pet is the Remote event
end
debounce = false
end
end)
Then I am searching for that name of the thing" in the playerâs character from the server side. Afterwards, changing the position.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")
EquipPet.OnServerEvent:Connect(function(player, name)
local char = player:WaitForChild("Character")
local humRoot = char:FindFirstChild("HumanoidRootPart")
-- realized you didnt define the actual player's character
player.Character:FindFirstChild(name):SetPrimaryPartCFrame(humRoot.CFrame) -- I am trying to position the pet near the player
print("Worked")
end)
Maybe? *Edit: Realized that you didnât define the actual playerâs character properly.
Is there an error in the developer console? If so, what is the error?
FireServer automatically sends the player parameter so you can take out that player parameter
@wakeupjavi Character is not a child of player, it is a property. You can instead do
char = player.Character or player.CharacterAdded:Wait()
Are you trying to get the playerâs character? If so, just use the code I sent to @wakeupjavi as the playerâs characterâs name is not âCharacterâ, but it is the playerâs username.
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")
for:
local EquipPet = ReplicatedStorage:FindFirstChild("EquipPet")
or add this between the variable and the remote event fire
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")
while EquipPet == nil do wait() end
EquipPet:FireServer(Clo1.Name)-- Equip pet is the Remote event
or, you could also try setting the variable before the MouseButton1Click function and see if it now fires properly
The âEquipPetâ variable might not have been set by the time it tries to fire the remote event, so⌠i hope this helps
Have you even tried what I suggested? A playerâs character is not named âCharacterâ, itâs the playerâs username. You may want to define char and humRoot inside the OnServerEvent function so it changes for every player who activates it, not one specific character.
--This is the now changed server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")
EquipPet.OnServerEvent:Connect(function(player, Clo1)
Clo1:SetPrimaryPartCFrame(humRoot.CFrame) -- I am trying to position the pet near the player
print("Worked")
local char = game.Workspace:WaitForChild("Character")
local humRoot = char:FindFirstChild("HumanoidRootPart")
end)