Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[FE] Works in studio but not in-game even though I used a RemoteEvent?

While in studio when you click the Gui button, it gives you a "pet". When I test it in-game it doesn't give the player a pet. I'm new to FE scripting and RemoteEvents, can someone tell me what I'm doing wrong?

Gui button:

script.Parent.MouseButton1Click:connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer()
end)
-- This is a local script

Script in ServerScriptService:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
local target = game.ReplicatedStorage.Pet
 if game.Players.LocalPlayer.character:FindFirstChild("Pet") == nil then
	local pet = target:Clone()
	pet.Parent = game.Players.LocalPlayer.Character
	pet.Script.Disabled = false
	end end) 
-- This is a regular script

Script in pet:

local char = script.Parent.Parent
local hum = char:FindFirstChild("Humanoid")
local torso = char:FindFirstChild("Torso")
local pet = script.Parent

local maxFloat = 1
local floatInc = 0.025
local sw = false
local fl = 0

while true do
	wait()
	if not sw then
		fl = fl + floatInc
		if fl >= maxFloat then
			sw = true
		end
	else
		fl = fl - floatInc
		if fl <=-maxFloat then
			sw = false
		end
	end
	if pet ~= nil and hum ~= nil and torso ~= nil then
		if hum.Health >= 0 then
			local cf = torso.CFrame * CFrame.new(3,2+fl,3)
			pet.BodyPosition.Position = Vector3.new(cf.x,cf.y,cf.z)
			pet.BodyGyro.CFrame = torso.CFrame * CFrame.new(3,0,-3)
		else
			break
		end
	end
end

-- Also, a regular script

3 comments

0

I'm having similar problems, just not in FE.

0

In server script, you can't do game.Players.LocalPlayer. This is done in the client side, local script. Also, add variables when identifying the RemoteEvent, and the pet. Example: game:GetService("ReplicatedStorage"):WaitForChild("ExampleEvent") and game:GetService("ServerStorage"):WaitForChild("Pet"). Add the pet in ServerStorage, that way the client doesn't download the pet and waste memory.

0

How do I fix the server script?

1 answer

✓ Accepted answer
local Event = game:GetService("ReplicatedStorage"):WaitForChild("Event")
local target = game:GetService("ServerStorage"):WaitForChild("Pet")

Event.OnServerEvent:Connect(function(player)
 if player.character:FindFirstChild("Pet") == nil then
    local pet = target:Clone()
    pet.Parent = player.Character
    pet.Script.Disabled = false
    end end) 

When you call :FireServer(), the player is added as parameter. Try this code, or edit it since it's improved a bit. Tell me if there's any issues.

2 comments

0

Edit the 'Event' variable and put RemoteEvent, made a mistake there.

0

Thank you so much!

This discussion is preserved as it was. New answers, comments, and votes are closed.