Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this script give everyone the resource instead of just one person?

So i'm trying to make a basic ore collection. The collection works by a pickaxe hitting a rock. If the rock name corresponds to the script, give them that ore.

That all works fine... However, my scripts seems to give the resource to all players rather than just one...

Any ideas?

game.ReplicatedStorage.Oof.OnServerEvent:Connect(function(player)
local playersname = player.Name
local FolderName = game.ServerScriptService:FindFirstChild(playersname)
if FolderName then

  if script.Parent.InUse.Value == false then
    script.Parent.InUse.Value = true
    local kickAnimation = Instance.new("Animation")
    kickAnimation.AnimationId = "rbxassetid://704173649"
    local kickAnimationTrack = player.Character.Humanoid:LoadAnimation(kickAnimation)
    kickAnimationTrack:Play()
    wait(1.5)
    script.Parent.InUse.Value = false



  else
    print("Nope")
  end
end

local function Kill (hit)


  if hit.Parent.Name == "Rock" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Stone.Value = FolderName.Stone.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Stone.TextButton.Text = "Stone: ".. FolderName.Stone.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Rock + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    print(playersname)
    B.Disabled = false
    wait(1.5)
    B:Destroy()
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)
  end

  if hit.Parent.Name == "Copper" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Copper.Value = FolderName.Copper.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Copper.TextButton.Text = "Copper: ".. FolderName.Copper.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Copper + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)
    B:Destroy()

  end

  if hit.Parent.Name == "Tin" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Tin.Value = FolderName.Tin.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Tin.TextButton.Text = "Tin: ".. FolderName.Tin.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Tin + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    script.Parent.Debounce.Value = false
    B:Destroy()
    print(script.Parent.Debounce.Value)

  end

  if hit.Parent.Name == "Gold" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Gold.Value = FolderName.Gold.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Gold.TextButton.Text = "Gold: ".. FolderName.Gold.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Gold + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    B:Destroy()
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)

  end

  if hit.Parent.Name == "Iron" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Iron.Value = FolderName.Iron.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Iron.TextButton.Text = "Iron: ".. FolderName.Iron.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Iron + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    B:Destroy()
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)

  end


  if hit.Parent.Name == "Clay" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Clay.Value = FolderName.Clay.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Clay.TextButton.Text = "Clay: ".. FolderName.Clay.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Clay + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    B:Destroy()
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)

  end

  if hit.Parent.Name == "Coal" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Coal.Value = FolderName.Coal.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Coal.TextButton.Text = "Coal: ".. FolderName.Coal.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Coal + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    B:Destroy()
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)

  end



end
script.Parent.Handle.Touched:Connect(Kill)
end)

Thank you.

3 comments

1

I am very sorry to tell you that not a lot of people are going to read this HUGE 149 lines script and try to find any mistakes. Try finding the problematic part.

0
  • on the above comment
0

Here

1 answer

✓ Accepted answer

You have made a folder in the ServerScriptService, in which the value of the resources are stored. Good idea, but did you make one folder per player??? If so, then I only have an idea to solve it that you may not like. It's easier to make the folder in the player and not in the ServerScriptService, as if you were doing a leaderstats:

game.Players.PlayerAdded:Connect(function(player)
local FolderName = Instance.new("Folder", player)
FolderName.Name = player.Name
local Coal = Instance.new("IntValue", FolderName)
Coal.Name = "Coal"
local Copper = Instance.new("IntValue",FolderName)
Copper.Name = "Copper"
local Iron = Instance.new("IntValue", FolderName)
Iron.Name = "Iron"
local Tin = Instance.new("IntValue", FolderName)
Tin.Name = "Tin"
local Gold = Instance.new("IntValue", FolderName)
Gold.Name = "Gold"
local Clay = Instance.new("IntValue", FolderName)
Clay.Name = "Clay"
local Rock = Instance.new("IntValue", FolderName)
Rock.Name = "Rock"
end)

So, I tried it myself and it works, your code should be like this (don't forget my code):

game.ReplicatedStorage.Oof.OnServerEvent:Connect(function(player)
--[Eternalove_fan32
local FolderName = Instance.new("Folder", player)
FolderName.Name = player.Name
local Coal = Instance.new("IntValue", FolderName)
Coal.Name = "Coal"
local Copper = Instance.new("IntValue",FolderName)
Copper.Name = "Copper"
local Iron = Instance.new("IntValue", FolderName)
Iron.Name = "Iron"
local Tin = Instance.new("IntValue", FolderName)
Tin.Name = "Tin"
local Gold = Instance.new("IntValue", FolderName)
Gold.Name = "Gold"
local Clay = Instance.new("IntValue", FolderName)
Clay.Name = "Clay"
local Rock = Instance.new("IntValue", FolderName)
Rock.Name = "Rock"
--Eternalove_fan32]
local playersname = player.Name
local FolderName = player:FindFirstChild(playersname) -- Eternalove_fan32 was here (i modifie here your code)
if FolderName then

  if script.Parent.InUse.Value == false then
    script.Parent.InUse.Value = true
    local kickAnimation = Instance.new("Animation")
    kickAnimation.AnimationId = "rbxassetid://704173649"
    local kickAnimationTrack = player.Character.Humanoid:LoadAnimation(kickAnimation)
    kickAnimationTrack:Play()
    wait(1.5)
    script.Parent.InUse.Value = false



  else
    print("Nope")
  end
end

local function Kill (hit)


  if hit.Parent.Name == "Rock" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Stone.Value = FolderName.Stone.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Stone.TextButton.Text = "Stone: ".. FolderName.Stone.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Rock + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    print(playersname)
    B.Disabled = false
    wait(1.5)
    B:Destroy()
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)
  end

  if hit.Parent.Name == "Copper" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Copper.Value = FolderName.Copper.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Copper.TextButton.Text = "Copper: ".. FolderName.Copper.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Copper + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)
    B:Destroy()

  end

  if hit.Parent.Name == "Tin" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Tin.Value = FolderName.Tin.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Tin.TextButton.Text = "Tin: ".. FolderName.Tin.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Tin + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    script.Parent.Debounce.Value = false
    B:Destroy()
    print(script.Parent.Debounce.Value)

  end

  if hit.Parent.Name == "Gold" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Gold.Value = FolderName.Gold.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Gold.TextButton.Text = "Gold: ".. FolderName.Gold.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Gold + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    B:Destroy()
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)

  end

  if hit.Parent.Name == "Iron" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Iron.Value = FolderName.Iron.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Iron.TextButton.Text = "Iron: ".. FolderName.Iron.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Iron + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    B:Destroy()
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)

  end


  if hit.Parent.Name == "Clay" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Clay.Value = FolderName.Clay.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Clay.TextButton.Text = "Clay: ".. FolderName.Clay.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Clay + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    B:Destroy()
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)

  end

  if hit.Parent.Name == "Coal" and script.Parent.Debounce.Value == false and script.Parent.InUse.Value == true then
    script.Parent.Debounce.Value = true
    FolderName.Coal.Value = FolderName.Coal.Value + 1
    player.PlayerGui.Inventory.Main.Frame.Items.Coal.TextButton.Text = "Coal: ".. FolderName.Coal.Value
    A = game.ServerScriptService.Notify
    B = A:Clone()
    B.Value.Value = "Coal + 1"
    B.Parent = player.PlayerGui
    hit.Parent.Damage.Value = hit.Parent.Damage.Value +1
    B.Disabled = false
    wait(1.5)
    B:Destroy()
    script.Parent.Debounce.Value = false
    print(script.Parent.Debounce.Value)

  end



end
script.Parent.Handle.Touched:Connect(Kill)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.