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

Why doesn't my RemoteEvent work?

Asked by
rexpex 45
8 years ago

I made a script that calls a RemoteEvent to determine what you are playing as. I put a value in the player's backpack so if it equals something you play as that character. But for some reason my RemoteEvent isn't working. Here is the script for calling the RemoteEvent.

    if Class.Value == 1 or
        Class.Value == 0 then
        game.Lightning.TestCharacter1.RemoteEvent:FireServer()
    end

and here is the script for the RemoteEvent

local player = game.Players.LocalPlayer
Folder = script.Parent
Event = Folder.IsChar1


script.Parent.RemoteEvent.OnServerEvent:connect(function()
                player.Character.LowerTorso.Transparency = 0

                    wait(0.01)

            player.Character.Head.face.Texture = "http://www.roblox.com/asset/?id=591414447"

    local Sleeve = Instance.new("Part", player.Character)
    Sleeve.CanCollide = false
    Sleeve.Anchored = false
    Sleeve.BrickColor = BrickColor.new("Maroon")
     Sleeve.Size = Vector3.new(1.11, 1.2, 1.07)
    local w = Instance.new("Weld", Sleeve)
    w.Part0 = player.Character.RightUpperArm
    w.Part1 = Sleeve
    w.C1 = CFrame.new(0,-0.36,0)

    local Sleeve2 = Instance.new("Part", player.Character)
    Sleeve2.CanCollide = false
    Sleeve2.Anchored = false
    Sleeve2.BrickColor = BrickColor.new("Maroon")
     Sleeve2.Size = Vector3.new(1.11, 1.2, 1.07)
    local w = Instance.new("Weld", Sleeve)
    w.Part0 = player.Character.LeftUpperArm
    w.Part1 = Sleeve2
    w.C1 = CFrame.new(0,-0.36,0)

    local Tanktop = game.ReplicatedStorage.Union:Clone()
            Tanktop.Parent = player.Character
         local w = Instance.new("Weld", Sleeve)
        w.Part0 = player.Character.UpperTorso
        w.Part1 = Tanktop
        w.C1 = CFrame.new(0,0.18,0)

            local UpPant = Instance.new("Part", player.Character)
        UpPant.CanCollide = false
        UpPant.Anchored = false
        UpPant.BrickColor = BrickColor.new("Really black")
        UpPant.Size = Vector3.new(1.08, 1.21,1.04)
            local w = Instance.new("Weld", player.Character)
        w.Part0 = player.Character.LeftUpperLeg
        w.Part1 = UpPant
        w.C0 = CFrame.new(0,0.25,0)

            local UpPant2 = Instance.new("Part", player.Character)
        UpPant2.CanCollide = false
        UpPant2.Anchored = false
        UpPant2.BrickColor = BrickColor.new("Really black")
        UpPant2.Size = Vector3.new(1.08, 1.29,1.04)
            local w = Instance.new("Weld", player.Character)
        w.Part0 = player.Character.RightUpperLeg
        w.Part1 = UpPant2
        w.C0 = CFrame.new(0,0.15,0)

        local LowPant = Instance.new("Part", player.Character)
        LowPant.CanCollide = false
        LowPant.Anchored = false
        LowPant.BrickColor = BrickColor.new("Really black")
        LowPant.Size = Vector3.new(1.08, 1.23,1.04)
            local w = Instance.new("Weld", player.Character)
        w.Part0 = player.Character.RightLowerLeg
        w.Part1 = LowPant
        w.C0 = CFrame.new(0,0,0)

        local LowPant1 = Instance.new("Part", player.Character)
        LowPant1.CanCollide = false
        LowPant1.Anchored = false
        LowPant1.BrickColor = BrickColor.new("Really black")
        LowPant1.Size = Vector3.new(1.08, 1.21,1.04)
            local w = Instance.new("Weld", player.Character)
        w.Part0 = player.Character.LeftLowerLeg
        w.Part1 = LowPant1
        w.C0 = CFrame.new(0,0,0)

end)

print("works")

^ is suppose to tell me if every part is welded to the player.

0
OnServerEvent is used inside ServerScripts. OnClientEvent is used in localscripts. RubenKan 3615 — 8y
0
So do i attach OnClientEvents into the starterpack or something? rexpex 45 — 8y

2 answers

Log in to vote
2
Answered by 8 years ago

A Server Event should be fired in a local script and handled in a server script as I can see you handled it in local script which is wrong.

There is no need to make player variable because you get that variable by default using

RemoteEvent.OnServerEvent:connect(function(player) --- player variable

so basically FireServer() should be used in local script and OnServerEvent should be used in server script.

Read this article for more info

0
The player variable is absolutely required since he's connecting to the event from a local script, not a server script. P100D 590 — 8y
0
@P100D You are wrong. personal_ly 151 — 8y
0
FYI, .OnServerEvent() and .OnServerInvoke() automatically have the player passed as an argument UltimateRaheem 75 — 8y
Ad
Log in to vote
1
Answered by
P100D 590 Moderation Voter
8 years ago
Edited 8 years ago

You're using the wrong functions in the wrong scripts. You're firing the server from a server script, and then connecting to a server event from a local script.

Here's a rundown of RemoteEvent functions:


Use on server scripts only:

  • :FireClient(player) - Fires the event for only <player>
  • :FireAllClients() - Fires the event for all clients
  • .OnServerEvent(player) - Fires when the event is fired from client <player>

Use on local scripts only:

  • :FireServer() - Fires the event on the server
  • .OnClientEvent() - Fires when the event is fired from the server

Make sure you're using these right and your RemoteEvent should work properly.

Also see: http://wiki.roblox.com/index.php?title=RemoteFunction_and_RemoteEvent_Tutorial

Answer this question