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

Can you help me with my Giver Script?

Asked by 8 years ago

I am using this script for my Giver:

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 

game.Lighting.HyperLaser:clone().Parent = player.Backpack

wait(5)
debounce = false
end
end


script.Parent.Touched:connect(onTouch)

This used to work but all the sudden it doesnt work at all :( I have no idea what is wrong can you guys help me?

0
Any error in the output? funyun 958 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

There are a couple of mistakes, I did a complete rewrite of the script, made it more efficient, and more organized and easier to read. Consider reading the wiki this will help you a lot.

I have explained each and every thing to the best of my ability, hope I make everything clear for you.

Here's the script:

local debounce = false

function onTouch(hit) 
    local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- getting the player from his character
    if player.Character and not debounce then -- checking if the player's character exists and the debounce == false
        local char = player.Character  -- defining character for later use
        debounce = true 
        local weapon = game.Lighting.HyperLaser:clone() 
        weapon.Parent = char -- parenting the weapon to character
        wait(5)
        debounce = false
    end 
end

script.Parent.Touched:connect(onTouch)

Note: I highly recommend using ServerStorage, rather than Lighting, but I used Lighting anyway since you already had it like that.

Hope it helps!

0
I have a custom backback that disables the OG backpack and that is why it doesnt work, is there anyway to make it compatable? TixyScripter 115 — 8y
0
I believe you can parent the tool to the player's character, that would make the character have it already equipped. Unequipping and equipping it again would belong to the custom backpack system you already made. AbsoluteAxiom 175 — 8y
0
Could you edit your script on how I would do that? Sorry I dont need to be demanding I jsut havnt really handle the Core GUI's at all.... TixyScripter 115 — 8y
0
Edited AbsoluteAxiom 175 — 8y
View all comments (2 more)
0
Thanks, It worked great! I really appreciate the fact that you told me what the script did, so I can learn from it! TixyScripter 115 — 8y
0
No problem! Happy I could help AbsoluteAxiom 175 — 8y
Ad

Answer this question