Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Will you help me with my GUI tool giver script?

This is what I've tried:

local Tool = game.Lighting.Tool
local player = game.Players.LocalPlayer

function onClick()
	game.Workspace[player.Name].Torso.CFrame = CFrame.new(Vector3.new(0, 5, 0))
	if script.Parent.Visible == true then
		script.Parent.Parent:Destroy()
	end
end

function Give(player)
	Tool1 = Tool:clone()
	Tool1.Parent = player.Backpack
end


script.Parent.MouseButton1Click:connect(onClick)
script.Parent.MouseButton1Click:connect(Give)

This is in a regular script. Im teleporting correctly and the gui dissappears but I want it to give me a tool when I click the textbutton. And that is not working D: Currently the tool is located under Lighting but I'm not quite sure if that's where it should be. I'm also concerned about:

script.Parent.MouseButton1Click:connect(Give)

Please help! Any knowledge will be appreciated :D

2 answers

✓ Accepted answer
local Tool = game.Lighting.Tool
local player = game.Players.LocalPlayer

function onClick()
    player.Character.Torso.CFrame = CFrame.new(Vector3.new(0, 5, 0))
	Tool1 = Tool:clone()
    Tool1.Parent = player.Backpack
    if script.Parent.Visible == true then
        script.Parent.Parent:Destroy()
    end
end


script.Parent.MouseButton1Down:connect(onClick)

A couple of things. First, LocalPlayer only works if it's in a local script. Second, you don't need two functions for the two things. I merged them both into one function. Third, player.Character is more efficient to use, it's the same thing but I prefer to use it. Finally, I use MouseButton1Down, rather then MouseButton1Click.

Hope this helps!

1 comment

0

Thanks so much :D

Tool1 = Tool:clone()
Tool1.Parent = player.Backpack

Is your problem.

It should just be Tool I think.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.