Level System giving Exp

I have made a level system (not leaderstat) but with a UI.

local player = game.Players.LocalPlayer
local xp = player:WaitForChild(“Exp”)
local level = player:WaitForChild(“levels”)
local maxExp = 100

xp.Changed:Connect(function()
if xp.Value >= maxExp then
script.Parent.Size = UDim2.new(xp.Value/maxExp,0,1,0)
wait(0.5)
xp.Value = xp.Value - maxExp
script.Parent.Size = UDim2.new(xp.Value/maxExp,0,1,0)
level.Value = level.Value + 1
else
script.Parent.Size = UDim2.new(xp.Value/maxExp,0,1,0)
end
end)

script.Parent.Size = UDim2.new(xp.Value/maxExp,0,1,0)
this is the script I made for the level UI

Currently I am trying to make a block that if u touch it it will give you XP
The current script I have is

local player = game.Players.LocalPlayer

local xp = player:WaitForChild(“Exp”)

local level = player:WaitForChild(“levels”)

local part = game.Workspace.FinishBricks.GrassThemeFinish

local function onPartTouched(otherPart)

– Get the other part’s parent

local partParent = otherPart.Parent

– Look for a humanoid in the parent

local humanoid = partParent:FindFirstChildWhichIsA(“Humanoid”)

if humanoid then

xp.Value = xp.Value + 15

end

end

This script is a local script I put in StarterGui.
I do not see why this is not working…
Can someone tell me why this is not working and how to fix it…

1 Like
  1. maybe you have not set a touched event for the touch part, or is it just after that.
  2. you should not put it in a local script, since it will only update for the client not for the server

I dont understand what you mean by the first one…

in order to check if a part is touched, you need to set a .Touched event. Here is the format

Part.Touched:Connect(function f)

here is an example

local function partTouched(otherPart) -- Function to be connected
	if otherPart.Parent:FindFirstChild("Humanoid") then -- Checks for Humanoid
		print("Part Touched by:", otherPart.Parent.Name) -- Prints the name of the player who touched the part
	end
end

wokspace.Part:Connect(partTouched) -- Set a .Touched Event and connect it to a function

I can see what the problem is:

You are trying to make a variable of a part using a local script. Maybe this would help:

--Put this in ServerScriptService (MUST be a normal script)--
local RmtEvent = Instance.new("RemoteEvent")
RmtEvent.Name = "XpEvent"
local part = game.Workspace.FinishBricks.GrassThemeFinish

local function onPartTouched(otherPart) --or rename the "otherPart" into hit

    – Get the other part’s parent

    local partParent = otherPart.Parent

    – Look for a humanoid in the parent

    local humanoid = partParent:FindFirstChildWhichIsA(“Humanoid”)

    if humanoid then

        RmtEvent:FireClient("humanoid")

    end

end

part.Touched:Connect(onPartTouched)

--And put this into your local script--
local RmtEvent = Instance.new("RemoteEvent")
RmtEvent.Name = "XpEvent"

RmtEvent.OnClientEvent:Connect(function()
    --Put your code here--
end)

I would also recommend looking up remote events. It would really help!