Player1 and Player2 gaining leaderstats issue

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? The Player who hits the part and throws the tool should be the Player to gain the Coins in leaderstats

  2. What is the issue? Player1 gains the Coins when Player2 should

  3. What solutions have you tried so far? Various methods of scripting

video attached to show script and details

LinkVideo

You will need to verify the person who touches the part, you can use :GetPlayerFromCharacter to do this:

The explanation for the issue is because .Touched replicates across clients since physics replicate as explained in detail here:

Also please use ``` and copy paste your script so we can help better next time.

--example
2 Likes

Thx ! This helped me.

‘’’
local part = script.Parent
local newZom1 = game.Workspace:WaitForChild(“newZom1”).Handle
local LocalPlayer = game:GetService(“Players”).LocalPlayer

debounce = false
part.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local char = plr.Character
if not debounce then
debounce = true
local canGet = true
if char and newZom1 and canGet then
print(“Our character touched the part!”)
print(plr.Name)
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 21
newZ1 = newZom1:Clone()
newZ1.Name = “newZ1”
newZ1.Parent = game.Workspace
newZ1.BrickColor = BrickColor.Random()
newZ1.Anchored = true
newZom1:Destroy()
wait(1)
return
end
debounce = false
end
end
end)
‘’’

2 Likes

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