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

How do I make my script work while holding the tool?

I am making a sandbox game that locks you in first person and I want to make one of my tools I have allow you to move your cursor when it is equipped. I don't want any of my other items to allow you to move your cursor in first person.

Here is my script:

local Tool = script.Parent

if Tool.Equipped then local plrGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")

local screenGui = Instance.new("ScreenGui", plrGui)

local txtButton = Instance.new("TextButton")
txtButton.BackgroundTransparency = 1
txtButton.Size = UDim2.new(0, 0, 0, 0)

txtButton.Modal = true

txtButton.Parent = screenGui

if Tool.Unequipped then
	txtButton.Modal = false
end

end

1 answer

✓ Accepted answer

Tool.Equipped and tool.Unequipped are events, not properties (which is how you are using them as)

This is what you wanna do:

local Tool = script.Parent
local plrGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local screenGui = Instance.new("ScreenGui", plrGui)
local txtButton = Instance.new("TextButton", screenGui)

txtButton.BackgroundTransparency = 1
txtButton.Size = UDim2.new(0, 0, 0, 0)

Tool.Equipped:Connect(function()
	txtButton.Modal = true
end)

Tool.Unequipped:Connect(function()
	txtButton.Modal = false
end)

1 comment

0

Thank you very much!

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