- What do you want to achieve? Keep it simple and clear!
A flashbang, that when thrown, spawns a part (a hitbox) that applies a gui to any characters screen that it touches
-
What is the issue? Include screenshots / videos if possible!
The script doesn’t seem to know what “player” is. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried adding an “if” statement that checks if player even exists. As expected, the flashbang function
I have also tried putting my code in a local script instead of a server script,
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Script below:
local AoE = script.Parent -- the hitbox that is spawned when you throw the flashbang.
local starterGui = game:GetService("StarterGui")
local gui = starterGui.FlashbangScreen:Clone() -- gui consisting of a frame with a white background.
local players = game:GetService("Players")
local function flashbang(touchingPart)
local humanoid, touchingCharacter = u.findHumanoid(touchingPart) --findHumanoid is a function in the module utility.
if humanoid and touchingCharacter and humanoid.Health > 0 then
local player = players:GetPlayerFromCharacter(touchingCharacter)
gui.Parent = player.PlayerGui -- this errors.
local count = 0
while count < 21 do -- a while loop.
wait(.1)
count += 1
gui.Frame.BackgroundTransparency += .05 -- making the gui disappear over time.
end
end
end
local function onTouch(partTable)
if #partTable > 0 then
for i,v in pairs (partTable) do
if v.Name == "HumanoidRootPart" then -- if there's a humanoidrootpart touching AoE, then run the flashbang function.
flashbang(v)
end
end
end
end
local partTable = workspace:GetPartsInPart(AoE) -- a table of what parts are touching the AoE
if #partTable > 0 then
onTouch(partTable) -- if there are parts touching AoE, run onTouch
end
Obviously, please do not respond with deprecated code. I am also not looking for ChatGPT answers.
Thank you for your help/time.
Cheers!