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

Tool disabled if picked up?

Picking up this weapon / having it spawned in my inventory makes it as if it's disabled - the cursor doesn't change, and the scripts inside don't run. I'm wondering if this is an issue with my script or not? These are the opening lines;

game.Players.LocalPlayer.CharacterAdded:wait()
local player = game.Players.LocalPlayer
local char = player.Character
local mouse = player:GetMouse()
local tool = script.Parent
local handle = script.Parent.Handle
local reloading = false

local equipped = false

script.Parent.Equipped:Connect(function()
	equipped = true
end)
script.Parent.Unequipped:Connect(function()
	equipped = false
end)

local mag = script.Parent.Handle.mag
local clip = script.Parent.Handle.clip

local outOfAmmo = false

local magMax = 50
local clipMax = 10

local debounce = false

local ignore = {workspace.doNotCollide,player.Character}

Thanks.

1 answer

✓ Accepted answer

The problem here is that the script is waiting for the character to spawn - when the script runs, the character already exists, so the code waits until the player respawns (but you won't be able to tell since the tool gets removed just before the new character is made).

So:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

-->> Character does not exist, it will wait for it to spawn
-->> But if it does exist, it simply sets the variable and no yielding happens

Hope I helped!

~TDP

1 comment

0

Aaahh that explains it! Thanks a lot!

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