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 7 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.

local Gems = game.Players.LocalPlayer.leaderstats.Gems



function onTouched(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) == game.Players.LocalPlayer then
Gems.Value = Gems.Value + 1
hit:Destroy()
print("Ads")
end
end

game.Workspace.Gem.Touched:connect(onTouched)



2 answers

Log in to vote
1
Answered by 7 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:

function onTouched(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then -- if the person exists then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- just a var
        local Gems = plr.leaderstats.Gems -- another var
        Gems.Value = Gems.Value + 1 -- +1 val
        print("Ads")
        script.Parent:Destroy() -- instead of hit.destroy, that'd destroy a body part. you mean script.Parent:Destroy()?
    end
end

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.

Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
local Gems = game.Players.LocalPlayer.leaderstats.Gems
function onTouched(hit, gemz)
if game.Players:GetPlayerFromCharacter(hit.Parent) == game.Players.LocalPlayer then
Gems.Value = Gems.Value + 1
gemz:Destroy()
print("Ads")
end
end
for i,v in pairs(game.Workspace:GetChildren()) do
if v.ClassName == "Part" then
if v.Name == "Gem" then
game.Workspace.Gem.Touched:connect(onTouched(v)
end
end
end


0
Didn't work :P RetroThieff 5 — 7y

Answer this question