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?
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