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

Player doesn't recieve item after being given?

Asked by
kjduck 0
4 years ago

ToolGivingSystem: (Script in ServerScriptService)

01local groupId = 6301077
02local ToolGive = Instance.new("RemoteEvent", game.ReplicatedStorage)
03ToolGive.Name = "GivePlayerTools"
04 
05function giveTools(plr, toolFolder, givePlayer)
06    print("Fired")
07    if plr:GetRankInGroup(groupId) > -1 then
08        print("Giving tools")
09        local tools = toolFolder:GetChildren()
10        for _, tool in pairs (tools) do
11            tool.Parent = givePlayer.Backpack
12            print("Given "..tool.Name)
13        end
14        toolFolder:Destroy()
15    end
16end
17 
18ToolGive.OnServerEvent:Connect(giveTools)

ToolGivingLocal: (LocalScript in StarterPlayerScripts)

01local gui = script:WaitForChild("ToolGiver")
02local toolButton = script:WaitForChild("Tool")
03local groupId = 6301077
04local plr = game.Players.LocalPlayer
05local mouse = plr:GetMouse()
06local givingEvent = game.ReplicatedStorage:WaitForChild("GivePlayerTools")
07 
08if plr:GetRankInGroup(groupId) > 254 then
09    wait(1)
10    script:Destroy()
11end
12 
13mouse.Button1Down:Connect(function()
14    local target = mouse.Target
15    if mouse.target ~= nil and target.Parent:FindFirstChild("HumanoidRootPart") then
View all 50 lines...
0
Are there any errors? cucucu0001 35 — 4y

1 answer

Log in to vote
0
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:

01local groupId = 6301077
02local ToolGive = Instance.new("RemoteEvent", game.ReplicatedStorage)
03ToolGive.Name = "GivePlayerTools"
04 
05function giveTools(plr, toolFolder, givePlayer)
06    local player = game.Players[givePlayer]
07    print("Fired")
08    if plr:GetRankInGroup(groupId) > -1 then
09        print("Giving tools")
10        local tools = toolFolder:GetChildren()
11        for _, tool in pairs (tools) do
12            tool.Parent = player.Backpack
13            print("Given "..tool.Name)
14        end
15        toolFolder:Destroy()
16    end
17end
18 
19ToolGive.OnServerEvent:Connect(giveTools)

Localscript:

01local gui = script:WaitForChild("ToolGiver")
02local toolButton = script:WaitForChild("Tool")
03local groupId = 6301077
04local plr = game.Players.LocalPlayer
05local mouse = plr:GetMouse()
06local givingEvent = game.ReplicatedStorage:WaitForChild("GivePlayerTools")
07 
08if plr:GetRankInGroup(groupId) > 254 then
09    wait(1)
10    script:Destroy()
11end
12 
13mouse.Button1Down:Connect(function()
14    local target = mouse.Target
15    if mouse.target ~= nil and target.Parent:FindFirstChild("HumanoidRootPart") then
View all 50 lines...
Ad

Answer this question