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

Can anyone help with an invisibility script?

Asked by 5 years ago
Edited 5 years ago

Ok, so after a few months of trying to come up with a solution on my own I am finally asking for some help. I am trying to make a code which allows players to hide inside of a part while they are standing inside of it, not unlike the bushes found in many MOBAs today. The code itself seems to work when testing locally or on a virtual server, however on a live server the code eventually breaks causing players to either be locked in an invisible or visible state depending on the state the player was in as the code breaks. As the code randomly breaks without throwing an error, I am having trouble pinpointing where the code fails or if there is a bug on the live version of Roblox being used on live servers as the bug has only ever shown on a live server. I would appreciate it if anyone can help find problems with the system I am currently using or any bugs with the code itself that may be causing the visibility lock bug. As additional information, this is a server side script. Here is the code for reference. ~~~~~~~~~~~~~~~~ local RunService = game:GetService("RunService") local player = script.Parent local root = player.HumanoidRootPart local humanoid = player:WaitForChild("Humanoid") local replicatedStorage = game:GetService("ReplicatedStorage")

local notInBush = Instance.new("BoolValue", player) notInBush.Name = "notInBush" notInBush.Value = true

function objectNotCollidingWith(part1, part2) --checks if two parts are not colliding local answer = 0 for _, object in pairs(part1:GetTouchingParts()) do if object.Name == part2 then answer = answer + 1 end end return answer end

function setTransparency(char, value) --sets the transparency of all parts of a player for _, child in pairs(char:GetChildren()) do if child:IsA('Accessory') and child:FindFirstChild("Handle") then child.Handle.Transparency = value elseif child:IsA('BasePart') then if child.name == 'HumanoidRootPart' then else child.Transparency = value end end end end

function hideInBush(hit) --makes player invisible if hit.name == 'Grass' then if player then local head = player:FindFirstChild("Head") local face = head:FindFirstChild("face") if head and game.Players:GetPlayerFromCharacter(player) and notInBush.Value == true and head.Transparency < 1 and player.isShooting.Value == false then for t = 0, 1, .25 do if face then face.Transparency = t end setTransparency(player, t) wait(0.025) end notInBush.Value = false end end end end

function doubleCheckGrassLeave() --makes player visible again if objectNotCollidingWith(root, "Grass") <= 0 and notInBush.Value == false then if player then local head = player:FindFirstChild("Head") local face = head:FindFirstChild("face") if head and game.Players:GetPlayerFromCharacter(player) and notInBush.Value == false and head.Transparency >= 1 then for t = 1, 0, -.25 do if face then face.Transparency = t end setTransparency(player, t) wait(0.025) end notInBush.Value = true end end end if humanoid.Health <= 0 then script:Destroy() script.Disabled = true end end

root.Touched:Connect(hideInBush) RunService.Heartbeat:Connect(doubleCheckGrassLeave) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Thank you in advance if you can offer any advice or help

0
many many word TheluaBanana 946 — 5y
0
why so looong TheluaBanana 946 — 5y
0
i agree with TheLua, you can reduce this script a lot.. really a lot, you can set the transparency of the body parts directly, and use FindFirstChildOfClass to do this with accessories.. maybe what is breaking this script, is that inside the player there isn't only accessories and parts, this is what i think darkzerobits 92 — 5y

Answer this question