im trying to make a script that runs if a player touches a part but idk how to
local parent_part = script.Parent
parent_part.Touched:Connect(function(hit)
print("parent part touched")
end)
ive done the same thing-ish but it doesnt work im kinda new to this so bear with me plz
local parentpart = script.Parent
parent_part.Touched:Connect(function(hit)
game.StarterGui.some.TextLabel.Text = "oddman"
end)
first off you can’t modify things in startergui. you need to get the player first local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
then to change the textlabel you can do Player.PlayerGui.some.TextLabel.Text
If you add a print("This runs")
in your function/touch event. Then you can make sure it works properly, that way you can figure out that this part does work:
parent:part.Touched:Connect(function(hit)
and it’s the code inside that’s something wrong with.
Another issue though, you have called your variable “parentpart”, but reference “parent_part”. Both needs to be exactly the same name, any capitalization or character difference, and you’re creating or referencing a different variable.
local parent_part = script.Parent
parent_part.Touched:Connect(function(hit)
local player = hit.Parent:GetPlayerFromCharacter()
if player then
player.PlayerGui.some.TextLabel.Text = "oddman"
end
end)