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

Why won't this Invisible tool work in servers?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

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

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

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!
0
Thanks! This helped a lot! yoshi8080 445 — 8y
Ad

Answer this question