Troubles with tool giver

so i’ve wanted to make a radio giver which is gives item upon pressing F, removes radio prop on client and gives player an actual tool. then upon player’s death the radio prop comes back in place.

im having troubles with tool give out and the radio prop’s comeback on death. tried searching for the answer here on forum but i couldn’t find anything that would help.

here’s the localscript which handles radio prop and gives player name to client

local UserInputService = game:GetService("UserInputService")
local ZePlayer = game.Players.LocalPlayer
local ZeMouse = ZePlayer:GetMouse()
local ZeBody = ZePlayer.Character
local ZeHeart = ZeBody.Humanoid
local alsoathing = nil
local clientcooldown = false
local Tower = workspace.Observation:WaitForChild("RadioGiver")
local radio = Tower:FindFirstChild("Handle")
local NOTIFICATION2 = Tower:WaitForChild("RadioGUIPart"):WaitForChild("BillboardGui");

-- skipping part with F prompt since there's no problems with it

UserInputService.InputBegan:Connect(function(p1, p2)
	if p1.KeyCode == Enum.KeyCode.F and thing ~= nil and not p2 and not ZeBody:FindFirstChildOfClass("Tool") then
		if alsoathing == "radio" and clientcooldown == false and NOTIFICATION2.Enabled == true then
			clientcooldown = true
			ZeHeart.WalkSpeed = 0
			wait();
			Tower.Radio:FireServer(ZePlayer.Name);
			wait(0.3);
			if radio and radio ~= nil then
				radio.Parent = game.ReplicatedStorage
				Tower:FindFirstChild("RadioGUIPart").Parent = game.ReplicatedStorage
			end
			ZeHeart.WalkSpeed = 16
			wait(0.3);
			clientcooldown = false
			return
		end
	end
end)

while wait() do
	workdarn()
end

ZeHeart.Died:Connect(function() -- this doesn't work for some reason and idk why
	if game.ReplicatedStorage:FindFirstChild("Handle") then
		local rad = game.ReplicatedStorage:FindFirstChild("Handle")
		rad.Parent = Tower
		local tow = game.ReplicatedStorage:FindFirstChild("RadioGUIPart")
		tow.Parent = Tower
	end
end)

and the server script which gives out radio

local repl = game:GetService("ReplicatedStorage")
local rad = repl:WaitForChild("Radio")
local radio = script.Parent:WaitForChild("Radio")

radio.OnServerEvent:Connect(function(name)
	local player = game.Players:WaitForChild(name)
	print("given out to ", name)
	local rad3 = rad:Clone()
	local shit = player:WaitForChild("Backpack")
	rad3.Parent = shit
end)

Server script gives out error “Infinite yield possible on ‘Players:WaitForChild(“Instance”)’ - Line 6” which i dont know how to fix. It should search for actual player name in Game.Players, however for some reason it searches for “Instance”.

On that line OnServerEvent:Connect(function(name) you already have the player so, instead of that do this

 radio.OnServerEvent:Connect(function(player)
	local player = game.Players:WaitForChild(player.Name)
	print("given out to ", name)
	local rad3 = rad:Clone().Parent = player.Backpack
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.