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

Why won't this Invisible tool work in servers?

This tool was to make the player who uses it has a invisible torso, but It only works in studio.

EDIT: Used UserInputService Instead

local Player = Game.Players.LocalPlayer
local Char = Player.Character
local Mouse = Player:GetMouse()
local Torso = Char:FindFirstChild'Torso'

	enabled = true

	game:GetService("UserInputService").InputBegan:connect(function(input,proc)
		if input.KeyCode == Enum.KeyCode.E then
	if enabled then
		enabled = false
	Torso.Transparency = 1
		wait(5)
			Torso.Transparency = 0
				enabled = true
								end
									end
										end)

No errors Why won't this tool work in a server?

Tool is a regular tool not requiring a handle and the script is a local script and I've tried a hopperbin

1 answer

✓ Accepted answer

##Problem

The script appears to be loading before the character and its elements began to load.


##Solution

I added a wait function to a CharacterAdded event to return the character once the Character was added. The script appears to be loaded and executed before the character can be added. Also, FindFirstChild was returning Torso as nil, so line 3 in the script below can act as a if then statement somewhat. It's basically going if FindFirstChild returns nil, then wait for the WaitForChild to find something.


##Final Script

local Player = game.Players.LocalPlayer
local Char = Player.CharacterAdded:wait()
local Torso = Char:FindFirstChild'Torso' or Char:WaitForChild'Torso'

enabled = true

game:GetService("UserInputService").InputBegan:connect(function(input,proc)
    if input.KeyCode == Enum.KeyCode.E then
        if enabled then
            enabled = false
            Torso.Transparency = 1
            wait(5)
            Torso.Transparency = 0
            enabled = true
        end
    end
end)

######Hopefully this answer helped. If it did, hit the upvote button and if this answered your question hit the Accept Answer button. If you have any questions feel free to comment below!

1 comment

0

Thanks! This helped a lot!

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