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

How can I make a giver do this? [UNANSWERED]

Asked by 10 years ago

So I am working on a sword fight for Player Points game and I do not want a map in it. Here let me explain to you. I want it to give you a sword when you step on a certain brick. Like I have a plate where they are supposed to fight but I cant get it to give just one sword. It gives swords every time they move I am trying to make it to where it only gives one and I don't know how I would make it work for game passes. Like when you have this game pass you get a Illumina not a regular sword.

Script that I have inside the Plate and the Weapon:

local debounce = false

function getPlayer(humanoid) 
local players = game.Players:children() 
for i = 1, #players do 
if players[i].Character.Humanoid == humanoid then return players[i] end 
end 
return nil 
end 

function onTouch(part) 

local human = part.Parent:findFirstChild("Humanoid") 
if (human ~= nil) and debounce == false then

debounce = true

local player = getPlayer(human) 

if (player == nil) then return end 

script.Parent:clone().Parent = player.Backpack

wait(2)
debounce = false
end
end


script.Parent.Parent.Touched:connect(onTouch) 

I have the sword put inside the brick and everything works but it constantly gives you more not one and it doesn't add a different kind of sword if they have the game pass D: Help please if you can!

1 answer

Log in to vote
0
Answered by 10 years ago

I would suggest to check if the player already has a sword. Also, I added the GamePass part, for more information, you can go here.

debounce = false

function getPlayer(humanoid) 
    local players = game.Players:children() 
    for i = 1, #players do 
        if players[i].Character.Humanoid == humanoid then return players[i] end 
    end 
    return nil 
end 

function onTouch(part) 
    local human = part.Parent:findFirstChild("Humanoid") 
    if (human ~= nil) and debounce == false then
        debounce = true
        local player = getPlayer(human) 
        if (player == nil) or (player.Backpack:FindFirstChild(script.Parent.Name)) or Player.Backpack:FindFirstChild("SpecialSwordName") then return end --Sorry, I don't know the name of your sword
        local HasPass = game:GetService("GamePassService"):PlayerHasPass(player, Insert_Pass_Id_Here)
        if HasPass then
            --put special sword cloning here
        else
            script.Parent:clone().Parent = player.Backpack
        end
        wait(2)
        debounce = false
    end
end


script.Parent.Parent.Touched:connect(onTouch) 
0
Thanks :) would this work if I was to put multiple game passes in it? TixyScripter 115 — 10y
Ad

Answer this question