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

Scoring system more than 1 onTouch needed but cant figure it out?

Asked by 8 years ago

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.

01local Gems = game.Players.LocalPlayer.leaderstats.Gems
02 
03 
04 
05function onTouched(hit)
06if game.Players:GetPlayerFromCharacter(hit.Parent) == game.Players.LocalPlayer then
07Gems.Value = Gems.Value + 1
08hit:Destroy()
09print("Ads")
10end
11end
12 
13game.Workspace.Gem.Touched:connect(onTouched)

2 answers

Log in to vote
1
Answered by 8 years ago

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:

01function 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
09end
10 
11script.Parent.Touched:connect(onTouched)

There is a few errors plus the whole source was changed to fit a server script inside of the gem.

Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago
01local Gems = game.Players.LocalPlayer.leaderstats.Gems
02function onTouched(hit, gemz)
03if game.Players:GetPlayerFromCharacter(hit.Parent) == game.Players.LocalPlayer then
04Gems.Value = Gems.Value + 1
05gemz:Destroy()
06print("Ads")
07end
08end
09for i,v in pairs(game.Workspace:GetChildren()) do
10if v.ClassName == "Part" then
11if v.Name == "Gem" then
12game.Workspace.Gem.Touched:connect(onTouched(v)
13end
14end
15end
0
Didn't work :P RetroThieff 5 — 8y

Answer this question