|
| 20 Nov 2017 04:27 PM |
I have a script where If a tool hits a block X times then it will give the player the item.
However, its multiplayer. How Would I determine the owner of the tool.
How would I set it up after this: ... if if hit.Parent.Name == "RustyPicax" ??????? ...
-How can I determine the owner of the tool? -Each player gets the same tool.
|
|
|
| Report Abuse |
|
|
| |
|
|
| 20 Nov 2017 05:13 PM |
Is it a physical hit you are talking about? Like bumping the handle of the tool against the block?
script.Parent.Touched:connect(function(hit) if (hit.Parent) then local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent) if (player) then --[[Whatever you want to do, the player variable is the player whose tool hit the block.]] end end return (nil); end) |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2017 05:13 PM |
Here is the full script: How do I make it give the UnrefinedIronOre to the player that owns the picax? I put a value in picax called "Owner" and set it to change to the localplayer; however, I am still unsure how to give the player the ore. hits = script.Parent.hits.Value hitsneeded = script.Parent.hitsneeded.Value Ore = game.ReplicatedStorage.UnrefinedIronOre local Reciever = ????????????????????? ------------------------------------- function Reset() script.Parent.CanCollide = true script.Parent.Transparency = 0 hits = 0 end ------------------------------------ function MineIronOre() script.Parent.CanCollide = false script.Parent.Transparency = 1 print "IronOreMined" end ------------------------------------- function onTouch(hit) if hit.Parent.Name == "RustyPicax" then hits = hits+1 script.Parent.Mine:Play() wait(0.5) else ---Coming Soon---Picaxe/Drill levels. end if hits > hitsneeded then MineIronOre() wait(5)Reset() end end
script.Parent.Touched:connect(onTouch)
|
|
|
| Report Abuse |
|
|
|
| 20 Nov 2017 05:15 PM |
| Yes 128Gigabytes. I will try your idea. |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2017 05:31 PM |
Do I implement it like this, or do I just copy exactly what you did?
I added:local PersonThatGetsOre = game.PlayerFromCharacter(hit.Parent.Parent) and Ore.Parent = PersonThatGetsOre.Backpack
Nothing happened? Do I have to define hit or something? ----------------------------------------------------------------
hits = script.Parent.hits.Value hitsneeded = script.Parent.hitsneeded.Value local Ore = game.ReplicatedStorage.UnrefinedIronOre:Clone() local PersonThatGetsOre = game.PlayerFromCharacter(hit.Parent.Parent) ------------------------------------- function Reset() script.Parent.CanCollide = true script.Parent.Transparency = 0 hits = 0 end ------------------------------------ function MineIronOre() script.Parent.CanCollide = false script.Parent.Transparency = 1 print "IronOreMined"
Ore.Parent = PersonThatGetsOre.Backpack end -------------------------------------------------------------------------- function onTouch(hit) if hit.Parent.Name == "RustyPicax" then hits = hits+1 script.Parent.Mine:Play() wait(0.5) else ---Coming Soon---Picaxe/Drill levels. end if hits > hitsneeded then MineIronOre() wait(5)Reset() end end
script.Parent.Touched:connect(onTouch) |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2017 07:35 PM |
| Bump. If you don’t want to spend time on this could someone link a tutorial or free model to look off of? |
|
|
| Report Abuse |
|
|
|
| 20 Nov 2017 09:46 PM |
Is this script inside the block or the tool itself? I'm assuming blocking, and that isn't how you should be doing it.
But if you wanna keep doing it that way you implemented my suggestion incorrectly, it needs to go inside the onTouch function you created not at the top of your script. |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2017 05:58 AM |
| The script is inside the block. When any block named “RustyPicax” touches the block I want it to give the ore the player. My problem is that every player owns the same tool. I needed to add a script that determines the owner of the tool that hit it. I will try your idea soon. |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2017 06:03 AM |
Ok so like this? hits = script.Parent.hits.Value hitsneeded = script.Parent.hitsneeded.Value local Ore = game.ReplicatedStorage.UnrefinedIronOre:Clone()
------------------------------------- function Reset() script.Parent.CanCollide = true sc########################## # # hits = 0 end ------------------------------------ function MineIronOre() script.Parent.CanCollide = false script.Parent.Transparency = 1 print "IronOreMined"
end -------------------------------------------------------------------------- function onTouch(hit) script.Parent.Touched:connect(function(hit) if (hit.Parent) then local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent) if (player) then if hit.Parent.Name == "RustyPicax" then hits = hits+1 script.Parent.Mine:Play() wait(0.5) else ---Coming Soon---Picaxe/Drill levels. end end return (nil); end) if hits > hitsneeded then MineIronOre() wait(5)Reset() end end
script.Parent.Touched:connect(onTouch) |
|
|
| Report Abuse |
|
|
|
| 21 Nov 2017 08:42 PM |
Put this inside the tool
script.Parent.Handled.Touched:connect(function(basePart) if (basePart.Name == "gold ore") then --[[Change to whatever you named it.]] local player = game.Players:FindFirstChild(script.Parent.Parent.Name) if (player) then basePart:Destroy() player.leaderstats.Gold.Value = (player.leaderstats.Gold.Value + 5) end end return (nil); end |
|
|
| Report Abuse |
|
|
|
| 22 Nov 2017 08:52 AM |
How would I define the IronOre that the tool touched? Is it already defined as basepart?
|
|
|
| Report Abuse |
|
|
| |
|