Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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?

001game.ReplicatedStorage.Oof.OnServerEvent:Connect(function(player)
002local playersname = player.Name
003local FolderName = game.ServerScriptService:FindFirstChild(playersname)
004if FolderName then
005 
006  if script.Parent.InUse.Value == false then
007    script.Parent.InUse.Value = true
008    local kickAnimation = Instance.new("Animation")
009    kickAnimation.AnimationId = "rbxassetid://704173649"
010    local kickAnimationTrack = player.Character.Humanoid:LoadAnimation(kickAnimation)
011    kickAnimationTrack:Play()
012    wait(1.5)
013    script.Parent.InUse.Value = false
014 
015 
View all 149 lines...

Thank you.

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. Sonnenroboter 336 — 5y
0
+ on the above comment Nowaha 459 — 5y
0
Here Eternalove_fan32 188 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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:

01game.Players.PlayerAdded:Connect(function(player)
02local FolderName = Instance.new("Folder", player)
03FolderName.Name = player.Name
04local Coal = Instance.new("IntValue", FolderName)
05Coal.Name = "Coal"
06local Copper = Instance.new("IntValue",FolderName)
07Copper.Name = "Copper"
08local Iron = Instance.new("IntValue", FolderName)
09Iron.Name = "Iron"
10local Tin = Instance.new("IntValue", FolderName)
11Tin.Name = "Tin"
12local Gold = Instance.new("IntValue", FolderName)
13Gold.Name = "Gold"
14local Clay = Instance.new("IntValue", FolderName)
15Clay.Name = "Clay"
16local Rock = Instance.new("IntValue", FolderName)
17Rock.Name = "Rock"
18end)

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

001game.ReplicatedStorage.Oof.OnServerEvent:Connect(function(player)
002--[Eternalove_fan32
003local FolderName = Instance.new("Folder", player)
004FolderName.Name = player.Name
005local Coal = Instance.new("IntValue", FolderName)
006Coal.Name = "Coal"
007local Copper = Instance.new("IntValue",FolderName)
008Copper.Name = "Copper"
009local Iron = Instance.new("IntValue", FolderName)
010Iron.Name = "Iron"
011local Tin = Instance.new("IntValue", FolderName)
012Tin.Name = "Tin"
013local Gold = Instance.new("IntValue", FolderName)
014Gold.Name = "Gold"
015local Clay = Instance.new("IntValue", FolderName)
View all 167 lines...
Ad

Answer this question