So I finally finished my scoring system and data saving, but when I put more than 1 Gem down it doesn't work. And I can't find out a way to make more than 1 onTouch without having to name them 1 by 1 which in the end wouldn't work.
01 | local Gems = game.Players.LocalPlayer.leaderstats.Gems |
02 |
03 |
04 |
05 | function onTouched(hit) |
06 | if game.Players:GetPlayerFromCharacter(hit.Parent) = = game.Players.LocalPlayer then |
07 | Gems.Value = Gems.Value + 1 |
08 | hit:Destroy() |
09 | print ( "Ads" ) |
10 | end |
11 | end |
12 |
13 | game.Workspace.Gem.Touched:connect(onTouched) |
Hey Retro,
Why don't you try a server script inside each of the gems? Inside the gem, you'd put a script similar to the local one. It would go something like this:
01 | function onTouched(hit) |
02 | if game.Players:GetPlayerFromCharacter(hit.Parent) then -- if the person exists then |
03 | local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- just a var |
04 | local Gems = plr.leaderstats.Gems -- another var |
05 | Gems.Value = Gems.Value + 1 -- +1 val |
06 | print ( "Ads" ) |
07 | script.Parent:Destroy() -- instead of hit.destroy, that'd destroy a body part. you mean script.Parent:Destroy()? |
08 | end |
09 | end |
10 |
11 | script.Parent.Touched:connect(onTouched) |
There is a few errors plus the whole source was changed to fit a server script inside of the gem.
01 | local Gems = game.Players.LocalPlayer.leaderstats.Gems |
02 | function onTouched(hit, gemz) |
03 | if game.Players:GetPlayerFromCharacter(hit.Parent) = = game.Players.LocalPlayer then |
04 | Gems.Value = Gems.Value + 1 |
05 | gemz:Destroy() |
06 | print ( "Ads" ) |
07 | end |
08 | end |
09 | for i,v in pairs (game.Workspace:GetChildren()) do |
10 | if v.ClassName = = "Part" then |
11 | if v.Name = = "Gem" then |
12 | game.Workspace.Gem.Touched:connect(onTouched(v) |
13 | end |
14 | end |
15 | end |