✓ Accepted answer
Hi Derpy,
I don't think .Touched event works in LocalScripts quite as well as ServerScripts. You don't need local player. You can just put the script in a ServerScript but, you need to make it in the Server. Also, LocalScripts don't work in the server, so I have no idea why you're using a LocalScript in the server. I mean, you must be using a LocalScript in the server because the giver is the parent of the LocalScript, and the giver must be in the Server, in this case the workspace, to be seen. So, just replace the LocalScript with a ServerScript. Also, you need to fix up your code a bit because it's wrong. Here, I'll give you an analysis of it down below.
####Analysis:
local hammer = game:GetService("ServerStorage"):WaitForChild("Hammer")
local giver = script.Parent
gave = false
giver.Touched:connect(function(hit)
if hit:FindFirstChild("Humanoid") then
if not gave then
local playerHammer = hammer:Clone()
playerHammer.Parent = game.Players.LocalPlayer.Backpack
gave = true
end
end
end)
####Here, I'll show you the changes you will have made afterwards:
local hammer = game:GetService("ServerStorage"):WaitForChild("Hammer");
local players = game:GetService("Players");
local giver = script.Parent;
giver.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = players:GetPlayerFromCharacter(hit.Parent);
local backpack = player:WaitForChild("Backpack");
if not backpack:FindFirstChild(hammer.Name) then
local playerHammer = hammer:Clone()
playerHammer.Parent = backpack;
end
end
end)
##Well, I hope I helped and have a wonderful day/night.
Thanks,
Best regards,
~~ KingLoneCat
2 comments
oh I see, thanks for helping man :D
Np