Proximity Prompt not Changing Text

Hi all. I’ve run into an issue when using proximity prompts. It’s worth noting that my scripting knowledge is extremely limited, but I’m just messing around to see what I can achieve.

This is my current setup:

image

This is the LocalScript:

local ProximityPrompt = script.Parent
local plr = game.Players.LocalPlayer

local function onPromptTriggered(ProximityPrompt, plr)
	game.StarterGui.ScreenGui.TextBox.Text = 'changed'
end

PPS.PromptTriggered:Connect(onPromptTriggered)

I’m not looking for someone to just write the fixed script and leave it at that - I want to know why it isn’t working. Any help would be greatly appreciated!

2 Likes

You need to change PlayerGui not startergui

local ProximityPrompt = script.Parent
local plr = game.Plaeyrs.LocalPlayer

local function onPromptTriggered(ProximityPrompt, plr)
	plr.PlayerGui.ScreenGui.TextBox.Text = 'changed'
end

PPS.PromptTriggered:Connect(onPromptTriggered)
1 Like

Also, local scripts dont work when put on parts in workspace, they work only when put in starterplayerscripts, startergui and few other places

Yes officer, this is the solution. Right here. :sunglasses:

1 Like

Couple things here:

local plr = game.Plaeyrs.LocalPlayer – You’ve mispelt “Players” here, which will prevent the script from running.

Anyways, the main issue here is you’re changing the StarterGui here, rather than the PlayerGui. You can think of StarterGui like a container, whenever a player joins, the StarterGui gets cloned to the PlayerGui. You can reference the Players PlayerGui by simply doing:

plr.PlayerGui.ScreenGui.TextBox.Text

Although, it may be even easier depending on where your script is located to just refrence the TextBox. (ie. script.Parent.TextBox.Text). Try to change the location of your script to right under the TextBox, and simply do script.Parent.TextBox.Text.

2 Likes

I’m not looking for someone to just write the fixed script and leave it at that - I want to know why it isn’t working. Any help would be greatly appreciated!

It’s right here

His script wont be working at all, because local scripts work only when parented to player or starter gui.

You can either change your script to a server script, or put it in starterplayerscripts

2 Likes

On god I didin’t even notice that in the screenshot :dizzy_face:

1 Like

Thanks for the quick help everyone. Was able to change the LocalScript to a Script, and then do the PlayerGui thing. Again, really appreciative for all the help. :slight_smile:

2 Likes

Yes, that’s why I recommended the change to right under the TextBox in my post, that way it’s much simpler to reference the TextBox. Either way, server script works fine for this as well.

2 Likes

Wait if you changed it to a Script then you can’t call for LocalPlayer anymore. :face_with_raised_eyebrow:

https://gyazo.com/9762c75b62418af1ab110f35cb1870de

I’m happy with it - works absolutely fine.