Announcement

Collapse
No announcement yet.

Problem with OnPlayerJoin Function

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem with OnPlayerJoin Function

    I have this code:
    Server side
    Code:
     [COLOR=#61afef]AddEvent[/COLOR][COLOR=#abb2bf]([/COLOR][COLOR=#98c379]"OnPlayerJoin"[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#c678dd]function[/COLOR][COLOR=#abb2bf]([/COLOR][COLOR=#abb2bf][I]player[/I][/COLOR][COLOR=#abb2bf])[/COLOR]
    [COLOR=#61afef]SetPlayerSpawnLocation[/COLOR][COLOR=#abb2bf](player, [/COLOR][COLOR=#d19a66]125773.000000[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#d19a66]80246.000000[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#d19a66]1645.000000[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#d19a66]90.0[/COLOR][COLOR=#abb2bf])[/COLOR]
    [COLOR=#61afef]Delay[/COLOR][COLOR=#abb2bf]([/COLOR][COLOR=#d19a66]10000[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#c678dd]function[/COLOR][COLOR=#abb2bf]([/COLOR][COLOR=#abb2bf][I]player[/I][/COLOR][COLOR=#abb2bf])[/COLOR]
    [COLOR=#c678dd]local[/COLOR][COLOR=#abb2bf] chars = {[/COLOR][COLOR=#d19a66]26[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#d19a66]27[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#d19a66]28[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#d19a66]29[/COLOR][COLOR=#abb2bf]}[/COLOR]
    [COLOR=#c678dd]local[/COLOR][COLOR=#abb2bf] r = [/COLOR][COLOR=#56b6c2]math.random[/COLOR][COLOR=#abb2bf]([/COLOR][COLOR=#d19a66]4[/COLOR][COLOR=#abb2bf])[/COLOR]
    [COLOR=#61afef]CallRemoteEvent[/COLOR][COLOR=#abb2bf](player, [/COLOR][COLOR=#98c379]"SetClientClothingPreset"[/COLOR][COLOR=#abb2bf], chars[r])[/COLOR]
    [COLOR=#c678dd]end[/COLOR][COLOR=#abb2bf])[/COLOR]
    [COLOR=#c678dd]end[/COLOR][COLOR=#abb2bf])[/COLOR]
    Client side
    Code:
     [COLOR=#61afef]AddRemoteEvent[/COLOR][COLOR=#abb2bf]([/COLOR][COLOR=#98c379]"SetClientClothingPreset"[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#c678dd]function[/COLOR][COLOR=#abb2bf] ([/COLOR][COLOR=#abb2bf][I]presetId[/I][/COLOR][COLOR=#abb2bf])[/COLOR]
    [COLOR=#61afef]SetPlayerClothingPreset[/COLOR][COLOR=#abb2bf]([/COLOR][COLOR=#61afef]GetPlayerId[/COLOR][COLOR=#abb2bf](), presetId)[/COLOR]
    [COLOR=#c678dd]end[/COLOR][COLOR=#abb2bf])[/COLOR]
    But i receive the following error on the console.

    Code:
    [error] [string "ttt/ttt_s.lua"]:12: bad argument #1 to 'CallRemoteEvent' (expected integer-like argument)
    How i can fix this ?
    A Command with the same code works.
    Code:
     [COLOR=#c678dd]function[/COLOR][COLOR=#61afef]cmd_new[/COLOR][COLOR=#abb2bf]([/COLOR][COLOR=#abb2bf][I]player[/I][/COLOR][COLOR=#abb2bf])[/COLOR]
    [COLOR=#c678dd]local[/COLOR][COLOR=#abb2bf] chars = {[/COLOR][COLOR=#d19a66]26[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#d19a66]27[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#d19a66]28[/COLOR][COLOR=#abb2bf], [/COLOR][COLOR=#d19a66]29[/COLOR][COLOR=#abb2bf]}[/COLOR]
    [COLOR=#c678dd]local[/COLOR][COLOR=#abb2bf] r = [/COLOR][COLOR=#56b6c2]math.random[/COLOR][COLOR=#abb2bf]([/COLOR][COLOR=#d19a66]4[/COLOR][COLOR=#abb2bf])[/COLOR]
    [COLOR=#61afef]CallRemoteEvent[/COLOR][COLOR=#abb2bf](player, [/COLOR][COLOR=#98c379]"SetClientClothingPreset"[/COLOR][COLOR=#abb2bf], chars[r])[/COLOR]
    [COLOR=#61afef]AddPlayerChat[/COLOR][COLOR=#abb2bf](player, [/COLOR][COLOR=#98c379]"New."[/COLOR][COLOR=#abb2bf])[/COLOR]
    [COLOR=#c678dd]end[/COLOR]
    [COLOR=#61afef]AddCommand[/COLOR][COLOR=#abb2bf]([/COLOR][COLOR=#98c379]"new"[/COLOR][COLOR=#abb2bf], cmd_new)[/COLOR]

    #2
    Try this ( tested ):

    Code:
    AddEvent("OnPlayerJoin", function(player)
        SetPlayerSpawnLocation(player, 125773.000000, 80246.000000, 1645.000000, 90.0)
        CreateCountTimer(function()
            local chars = {26, 27, 28, 29}
            local r = math.random(4)
            CallRemoteEvent(player, "SetClientClothingPreset", chars[r])
        end,1000,1)
    end)
    Last edited by Skydox; 01-14-2020, 08:00 PM.

    Comment

    Working...
    X