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

Remote Events not working properly?

Asked by 6 years ago
Edited 6 years ago

I decided to try remote events with my spawning script. However, they are not working as I'm new to remote events. The event does fire, the server script isn't picking it up though.

Server Script (in ReplicatedStorage):

train = game.ReplicatedStorage.C70Freight
Camera = workspace.CurrentCamera
DriveFrame = GUI.Screen.DriveFrame
Spawning = GUI.Screen.Spawning

script.Parent.Parent.Events.C70Spawn.OnServerEvent:connect(function(player)
        GUI = player.PlayerGui.MainMenuGui
        DriveFrame.Visible = false
        Spawning.Visible = true
        Spawning.Text = "Spawning..."
        wait(0.01)
        local clone = train:Clone()
        clone.Parent = workspace
        clone:MakeJoints()
        wait(1)
        player.Character.HumanoidRootPart.CFrame = CFrame.new(610.265, 6.551, -3143.202)
        Spawning.Visible = false
        player.CameraMode = "Classic"
        Camera.CameraType = "Custom"
        Camera.FieldOfView = 80
        wait(1)
        GUI.Screen.IntroMusic:Stop()
end)

LocalScript (in Gui)

Frame = script.Parent.Parent
C70 = Frame:WaitForChild("Set1")
Player = game.Players.LocalPlayer

function C70Clicked()
    if workspace:IsRegion3Empty(Region3.new(Vector3.new(467.505, 6.548, -3076.283), Vector3.new(1152.544, 6.559, -3298.865))) then
    game.ReplicatedStorage.Events.C70Spawn:FireServer()
    else
script.Parent.Text = "Spawn Occupied! Please Wait."
wait(1)
script.Parent.Text = "4 Wagons"
    end
end

C70.MouseButton1Click:connect(C70Clicked)
0
Scripts do not run in ReplicatedStorage. Try ServerScriptService instead. jackfrost178 242 — 6y
0
Ah right. CarlPlandog 20 — 6y
0
It works in Studio, but not in Client? CarlPlandog 20 — 6y
0
the client and the server is separated in game, press F9, go to client and server log and post the error if any fanofpixels 718 — 6y
0
I did end up fixing it, I forgot to publish the game lmao CarlPlandog 20 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Your problem is that you are trying to access the player from the server. This works fine in studio, but in the real game, the player's class is empty. The line

GUI = player.PlayerGui.MainMenuGui

would be the error point as the MainMenuGui would not exist from the server's point of view.

Hopefully this can clear some things up for you (the Remote Event works fine).

Ad

Answer this question