Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

help with localplayer and guis?

so i'm currently trying to make a script where when a ball (soccerball) drops on a block it changes a gui and cant get it to change anything, it doesn't show any errors, it just does absolutely nothing. here's the script

script.Parent.Touched:Connect(function(hit)
	if hit.Name == "soccerball" then
		game.Players.LocalPlayer.PlayerGui.thing.Frame.display.Text = "100"
	     end
	end)
	

yes it's in a local script, and it doesn't work in actual game or test mode

i'm very new to scripting so any help is greatly appreciated, thanks!

p.s not in experimental mode

2 comments

0

LocalScripts can only run in PlayerGui, Backpack, PlayerScripts, Player Character, and ReplicatedFirst. Also, from your script, there was no way to get the player.

1 answer

✓ Accepted answer

First. Put a RemoteEvent in ReplicatedStorage. Now your script should be like that. "Use GetPlayerFromCharacter to find the player who touched the part" (In ServerScript)

local PlayerService = game:GetService('Players')
local RStorageService = game:GetService('ReplicatedStorage')

script.Parent.Touched:Connect(function(hit)
     local Player = PlayerService:GetPlayerFromCharacter(hit.Parent)
     if Player then
           RStorageService.RemoteEvent:FireClient(Player)
     end
end)

Now. If you want the script to change the text of your UI. Insert a LocalScript in the Backpack or others player services. In this LocalScript. Write that.

local PlayerService = game:GetService('Players')
local RStorageService = game:GetService('ReplicatedStorage')

local Player = PlayerService.LocalPlayer
local PlayerGui = Player:WaitForChild('PlayerGui')

RStorageService.RemoteEvent.OnClientEvent:Connect(function()
      PlayerGui.thing.Frame.display.Text = "100"
end)

That is FilteringEnabled.

This discussion is preserved as it was. New answers, comments, and votes are closed.