Answered by
4 years ago Edited 4 years ago
For some reason, there's a problem when passing a player through a Remote Event, you should pass the player's Name property instead
Script:
01 | local groupId = 6301077 |
02 | local ToolGive = Instance.new( "RemoteEvent" , game.ReplicatedStorage) |
03 | ToolGive.Name = "GivePlayerTools" |
05 | function giveTools(plr, toolFolder, givePlayer) |
06 | local player = game.Players [ givePlayer ] |
08 | if plr:GetRankInGroup(groupId) > - 1 then |
10 | local tools = toolFolder:GetChildren() |
11 | for _, tool in pairs (tools) do |
12 | tool.Parent = player.Backpack |
13 | print ( "Given " ..tool.Name) |
19 | ToolGive.OnServerEvent:Connect(giveTools) |
Localscript:
01 | local gui = script:WaitForChild( "ToolGiver" ) |
02 | local toolButton = script:WaitForChild( "Tool" ) |
03 | local groupId = 6301077 |
04 | local plr = game.Players.LocalPlayer |
05 | local mouse = plr:GetMouse() |
06 | local givingEvent = game.ReplicatedStorage:WaitForChild( "GivePlayerTools" ) |
08 | if plr:GetRankInGroup(groupId) > 254 then |
13 | mouse.Button 1 Down:Connect( function () |
14 | local target = mouse.Target |
15 | if mouse.target ~ = nil and target.Parent:FindFirstChild( "HumanoidRootPart" ) then |
16 | local givingPlr = game.Players:GetPlayerFromCharacter(target.Parent) |
17 | local tools = plr.Backpack:GetChildren() |
18 | local currentGui = gui:Clone() |
19 | local givingTools = { } |
20 | local giveButton = currentGui:WaitForChild( "MainFrame" ):WaitForChild( "Give" ) |
21 | local replicatedFolder = Instance.new( "Folder" , game.ReplicatedStorage) |
23 | if plr.PlayerGui:FindFirstChild( "ToolGiver" ) then |
24 | plr.PlayerGui:FindFirstChild( "ToolGiver" ):Destroy() |
26 | currentGui.MainFrame.Player.Text = givingPlr.Name |
27 | currentGui.Parent = plr.PlayerGui |
28 | for _, tool in pairs (tools) do |
29 | local currentButton = toolButton:Clone() |
30 | currentButton.Text = tool.Name |
31 | currentButton.Parent = currentGui.MainFrame.Tools |
32 | currentButton.MouseButton 1 Click:Connect( function () |
33 | if currentButton.BackgroundTransparency = = 0.3 then |
34 | table.remove(givingTools, tool) |
35 | currentButton.BackgroundTransparency = 0.8 |
37 | table.insert(givingTools, tool) |
38 | currentButton.BackgroundTransparency = 0.3 |
42 | giveButton.MouseButton 1 Click:Connect( function () |
44 | for _, tool in pairs (givingTools) do |
45 | tool.Parent = replicatedFolder |
47 | givingEvent:FireServer(replicatedFolder, givingPlr.Name) |