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

Why won't this script work? (I need assistance ASAP)

Asked by 3 years ago
local part = script.Parent
local player = game.Players.LocalPlayer

if player.PlayerGui:FindFirstChild(“NPCmessage”) then
part:FindFirstChild(“ClickDetector”):Destroy()
else
local ClickDetector = Instance.new(“ClickDetector”)
ClickDetector.Parent = part

ClickDetector.MouseClick:Connect(function()
local GUI = script.NPCmessage:Clone
GUI.Parent = Player.PlayerGui
end)
end
0
try using :Clone() instead of :Clone Leamir 3138 — 3y

2 answers

Log in to vote
0
Answered by
Ali_MTR 30
3 years ago

in line 2 it was player then in line 12 it became Player with a capital

so just change Player to player in line 12

0
also in line 11 try Clone() Ali_MTR 30 — 3y
0
Thanks guys!!! Really appreciate it! Sewnpai 0 — 3y
0
@Sewnpai If the answer solves your issue, mark it as accepted Leamir 3138 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

First of all, you made a spelling mistake with Clone(). After that, you accidentally set player to Player. Also PlayerGui may not have loaded yet so use WaitForChild to be on the safe side. Be a little careful next time!

local part = script.Parent
local player = game.Players.LocalPlayer -- Variable for player
local PlayerGui = player:WaitForChild("PlayerGui")

if PlayerGui:FindFirstChild(“NPCmessage”) then
part:FindFirstChild(“ClickDetector”):Destroy()
else
local ClickDetector = Instance.new(“ClickDetector”)
ClickDetector.Parent = part

ClickDetector.MouseClick:Connect(function()
local GUI = script.NPCmessage:Clone()
GUI.Parent = PlayerGui  -- Set's the GUI 
end)
end
0
What's with the “ rather than " or ' FlabbyBoiii 81 — 3y

Answer this question