I’m having issues with my Script not firing properly to my localscript.
Script:
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local checkpoint = script.Parent
function onTouched(hit)
if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then
local RS = game.ReplicatedStorage
local levelDef = RS.level
levelDef.Value = 1
print(levelDef.Value)
local remoteEvent = RS:FindFirstChildOfClass("RemoteEvent")
local function updateUI()
print("fire")
remoteEvent:FireClient()
end
Players.PlayerAdded:Connect(updateUI)
----- the rest of the script (unimportant)
localScript
local RS = game.ReplicatedStorage
local levelDef = RS.level.Value
local levelName = script.Parent.LName
local levelNumber = script.Parent.Number
local Players = game:GetService("Players")
local remoteEvent = RS:FindFirstChildOfClass("RemoteEvent")
local player = Players.LocalPlayer
local function updateUI()
--[[
normally it says:
"uh oh"
"something went wrong"
as the default text on the TextLabel
]]--
if levelDef == 0 then
levelName.Text = "erm"
levelNumber.Text = "the game's kinda working but not properly!"
end
if levelDef == 1 then
levelName.Text = "Level Name"
levelNumber.Text = "Level Number"
end
end
remoteEvent.OnClientEvent:Connect(updateUI)
And a recording showing that level == 1 however the event isn’t firing. This is also obvious due to it not printing “Fire”
[recording failed to upload][will retry soon]
the UI still says “uh oh” and doesnt even go to “erm”
function onTouched(hit)
if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then
-----
local player = Players:GetPlayerFromCharacter(hit.Parent)
local RS = game.ReplicatedStorage
local levelDef = RS.level
levelDef.Value = 1
print(levelDef.Value)
local remoteEvent = RS:FindFirstChildOfClass("RemoteEvent")
local function updateUI()
print("fire")
remoteEvent:FireClient(player)
end
Players.PlayerAdded:Connect(updateUI)
----- eos
It really depends on what you update. Use connections that relate to the things that will change and needs updating (for now it is only level so connect the .Changed event of the level object)