IT1024
(YEETYSON)
January 8, 2023, 11:26pm
#1
I made this script for my gasa4 game that when a player touches a part it makes a ui apear but its not working and theres not errors
its a local script in startergui
local part1 = game.Workspace.CarNPC.Car.Car.CarBody
local part2 = game.Workspace.CarNPC.Car.Car.CarBody
local part3 = game.Workspace.CarNPC.Car.Car.CarBody
local EndingUI = game.StarterGui.EndingUI
part1.Touched:Connect(function()
wait(0.1)
EndingUI.Enabled = true
EndingUI.TextLabel.Text = "HitByCar"
EndingUI.TextLabel1.Text = "Ending"
part2.Touched:Connect(function()
wait(0.1)
EndingUI.Enabled = true
EndingUI.TextLabel.Text = "HitByCar"
EndingUI.TextLabel1.Text = "Ending"
part3.Touched:Connect(function()
wait(0.1)
EndingUI.Enabled = true
EndingUI.TextLabel.Text = "HitByCar"
EndingUI.TextLabel1.Text = "Ending"
end)
end)
end)
also if I change the line 4 variable to script.parent it just makes the ui apear without touching the part would I have to add an
else EndingUI.Enabled = false?
1 Like
You are declaring the Template of the GUI you want to change its Enabled
property, Not the GUI that is visible and controllable to the player itself.
You would declare the EndingUI
as it was in the PlayerGui
container.
Here is an example:
local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player.PlayerGui
local EndingUI = PlayerGui.EndingUI
1 Like
IT1024
(YEETYSON)
January 9, 2023, 12:13am
#4
im not sure what you mean by template?
All the things that are in the StarterGui
container are cloned to the player’s PlayerGui
container (there are some exceptions).
You can learn more on this documentation page .
IT1024
(YEETYSON)
January 9, 2023, 12:17am
#6
ah i get it now ok
so is that all i would have to do?
i dont know how to code at all lol making this script was already a challenge
but i tested it and the ui still randomly apeared
local part1 = game.Workspace.CarNPC.Car.Car.CarBody
local part2 = game.Workspace.CarNPC.Car.Car.CarBody
local part3 = game.Workspace.CarNPC.Car.Car.CarBody
local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player.PlayerGui
local EndingUI = PlayerGui.EndingUI
part1.Touched:Connect(function()
wait(1)
EndingUI.Enabled = true
EndingUI.TextLabel.Text = "HitByCar"
EndingUI.TextLabel1.Text = "Ending"
part2.Touched:Connect(function()
wait(1)
EndingUI.Enabled = true
EndingUI.TextLabel.Text = "HitByCar"
EndingUI.TextLabel1.Text = "Ending"
part3.Touched:Connect(function()
wait(1)
EndingUI.Enabled = true
EndingUI.TextLabel.Text = "HitByCar"
EndingUI.TextLabel1.Text = "Ending"
end)
end)
end)
Yes, the GUI ‘EndingUI
’ is correctly declared.
Recheck your connections and other stuff that makes it enabled.
Just noting, you’re not making it invisible again…
1 Like
IT1024
(YEETYSON)
January 9, 2023, 12:22am
#8
yes I know im not making it invisible again its gonna stay on the players screen but i only have 1 script to activaet the ui and thats it im also not touching the part and its still making the ui apear not sure why
could you use like an else EndingUI.enabled = false so that it stays false until you touch the car
Check if it is enabled by default in the StarterGui
.
IT1024
(YEETYSON)
January 9, 2023, 12:24am
#10
its not it doesnt apear as soon as i start the game but it randomly apears
EgizianoEG
(Egiziano)
January 9, 2023, 12:26am
#11
There might be another script that is enabling it?!
If the parts are correctly positioned and sized, I don’t see a problem in the script you provided actually.
IT1024
(YEETYSON)
January 9, 2023, 12:27am
#12
ya this is really annoying ive been spending like 3 hours trying to fix this and I gotta realese my game today
I dissabled the script to make the ui apear and it stopped apearing so its gotta be the script
EgizianoEG
(Egiziano)
January 9, 2023, 12:30am
#13
Check the connections, then.
Just wait a moment…
You’re connecting the touched events in a wrong way (the ends).
Here is the modified script:
local part1 = game.Workspace.CarNPC.Car.Car.CarBody
local part2 = game.Workspace.CarNPC.Car.Car.CarBody
local part3 = game.Workspace.CarNPC.Car.Car.CarBody
local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player.PlayerGui
local EndingUI = PlayerGui.EndingUI
part1.Touched:Connect(function()
wait(1)
EndingUI.Enabled = true
EndingUI.TextLabel.Text = "HitByCar"
EndingUI.TextLabel1.Text = "Ending"
end)
part2.Touched:Connect(function()
wait(1)
EndingUI.Enabled = true
EndingUI.TextLabel.Text = "HitByCar"
EndingUI.TextLabel1.Text = "Ending"
end)
part3.Touched:Connect(function()
wait(1)
EndingUI.Enabled = true
EndingUI.TextLabel.Text = "HitByCar"
EndingUI.TextLabel1.Text = "Ending"
end)
Side note: use task.wait()
instead of the deprecated wait()
1 Like
IT1024
(YEETYSON)
January 9, 2023, 12:33am
#14
oh lemme try this really hope it works
IT1024
(YEETYSON)
January 9, 2023, 12:38am
#15
still doesnt work the weird thing is it doesnt apear when i do touch the car but it will randomly apear
EgizianoEG
(Egiziano)
January 9, 2023, 12:40am
#16
Try to check the position and size properties of the declared parts.
Also, why are you connecting the touched event three times on a single part?
1 Like
IT1024
(YEETYSON)
January 9, 2023, 12:41am
#17
its actully multiple parts just with the same name im changing the name tho since that might be the problem
IT1024
(YEETYSON)
January 9, 2023, 12:47am
#18
I decided to try and but the script under the part that triggers the ending
local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player.PlayerGui
local EndingUI = PlayerGui.EndingUI
script.Parent.Touched:Connect(function()
wait(1)
EndingUI.Enabled = true
EndingUI.TextLabel.Text = "HitByCar"
EndingUI.TextLabel1.Text = "Ending"
end)
and i got the error
attempted to index nil with player.playgergui
IT1024
(YEETYSON)
January 9, 2023, 12:48am
#19
the good news is it seems that its not randomly appearing anymore
maybe i would have to do player.localplayer.playergui?
hkep
(hkep)
January 9, 2023, 12:51am
#20
It looks like part1 == part2 == part3