Creating a System that gives someone an item

Well, I guess you could switch back to my older reply here.

Yeah I did but it doesn’t seem to give the item to the player when you click the block.

Script in block:

amount = 10
currencyname = "Points"

local tool = game.ServerStorage["ParkourTrophy"]
local klone = tool
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
script.Parent.ClickDetector.MouseClick:connect (function(plr)
if klone.Parent ~= plr.StarterPack then
remoteEvent:FireClient(plr, tool)
for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild("leaderstats") and v then
			v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
		end
end
else
end
end)

Local Script in starter player scripts:

local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
remoteEvent.OnClientEvent:Connect(function(tool)
local klone = tool:Clone()
klone.Parent = game:GetService("StarterPack")
end)

Remote event in Replicated Strogae and the Reward called “parkour trophy” in server storage.

Try changing these:

klone = tool to klone = tool:Clone()
remoteEvent:FireClient(plr, tool) to remoteEvent:FireClient(plr, klone)

And in the LocalScript, change these:

Remove the line: local klone = tool.Clone()
remoteEvent.OnClientEvent(tool) to remoteEvent.OnClientEvent(klone)
klone.Parent = game.StarterPack to klone.Parent = game.Players.LocalPlayer.Backpack

If it still doesn’t work, message me.

Edit: I clearly told you that plr.StarterPack won’t work, why are you still using the if statement to check if the tool is parented to the plr.StarterPack? That’s the issue.

@pranvexploder NO it won’t work, I said that if you use a local script you can’t access ServerStorage, as it can only be accessed Server - side.

Replicated Storage should be used when both the Client and Server have to access its contents, otherwise ServerStorage is not only a more secure method for storing stuff, but improves loading time too when used over Replicated Storage as it reduces Network traffic and isn’t replicated .

Well it does half of what it is supposed to do now that I replaced StarterPack with Backpack it now gives the points but not the tool trophy, would the reason for that be because I should put something other than Backpack?

Could you show me the current script?

Script:

amount = 10
currencyname = "Points"

local tool = game.ServerStorage["ParkourTrophy"]
local klone = tool:Clone()
local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
script.Parent.ClickDetector.MouseClick:connect (function(plr)
if klone.Parent ~= plr.Backpack then
remoteEvent:FireClient(plr, klone)
for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild("leaderstats") and v then
			v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
		end
end
else
end
end)

Local Script:

local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
remoteEvent.OnClientEvent:Connect(function(klone)

klone.Parent = game:GetService("StarterPack")
end)
1 Like

So any idea what the issue is?

Are you still here or have you left?