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

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

Asked by 6 years ago

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
0
I'm having similar problems, just not in FE. Kerizax 0 — 6y
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. liteImpulse 47 — 6y
0
How do I fix the server script? Michael_TheCreator 166 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
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.

0
Edit the 'Event' variable and put RemoteEvent, made a mistake there. liteImpulse 47 — 6y
0
Thank you so much! Michael_TheCreator 166 — 6y
Ad

Answer this question