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

Why does my remote function display players name twice?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make it so my weapon from my camera can be cloned and shown to other players but when I do my script I have a print name to see if things are working but it prints my name twice even though I changed the value? I don't know here.

Local Script-

local servergun = rep.Events.GetGun:InvokeServer(player,pri, sec)
if servergun == true then
    print("YaY")
end

Server Script-

game.ReplicatedStorage.Events.GetGun.OnServerInvoke = function(player, pri, sec)
        print(player.Character.Name)
        print(pri.Name)
        local function getgun()
        local servergun = game.ReplicatedStorage["Weapon Models"][pri.Name]:Clone()
        servergun.Parent = player.Character
        local weld = Instance.new("Weld", player.Character.RightHand)
        weld.Part0 = player.Character.RightHand
        weld.Part1 = player.Character[pri.Name].Body
        end
        return true
    end

I'm not good with these so I don't understand what I'm doing wrong! Here's the output

GameBoyOtaku GameBoyOtaku YaY

so it does work kinda but it's showing my name twice... why though?

0
is pri.Name the player's name? User#21908 42 — 5y
0
pri is a primary weapon it's an object that's in the camera GameBoyOtaku 63 — 5y

1 answer

Log in to vote
1
Answered by
aazkao 787 Moderation Voter
5 years ago
Edited 5 years ago

I guess you are expecting the second print to be whatever "pri" is, the reason its not whatever "pri" is and instead is the players name is because when you call InvokeServer, the player argument from InvokeServer gets assigned to the "pri" parameter in OnServerInvoke.

The reason is that the first parameter of OnServerInvoke is always the player that called the function, so when you call InvokeServer you dont actually have to put the player argument in, just put pri and sec

local servergun = rep.Events.GetGun:InvokeServer(pri, sec)-- this 2 arguments will be assigned to the second and third parameter(pri and sec) of OnServerInvoke, the first argument of OnServerInvoke will always be the player
if servergun == true then
    print("YaY")
end





game.ReplicatedStorage.Events.GetGun.OnServerInvoke = function(player, pri, sec)
        print(player.Character.Name)
        print(pri.Name)
        local function getgun()
        local servergun = game.ReplicatedStorage["Weapon Models"][pri.Name]:Clone()
        servergun.Parent = player.Character
        local weld = Instance.new("Weld", player.Character.RightHand)
        weld.Part0 = player.Character.RightHand
        weld.Part1 = player.Character[pri.Name].Body
        end
        return true
    end
0
now it's saying pri is a nil valie. Pri is primary weapon and it's a cloned object GameBoyOtaku 63 — 5y
0
well i wont know what's wrong as you didnt show the whole code aazkao 787 — 5y
Ad

Answer this question