You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
when the player joins the game they cant use magic but when they use the promitxy promt they will get the attributes needed to do magic the server script basicaly jus gets the gui for the mana bar and makes it visable when the player gets magic -
What is the issue? Include screenshots / videos if possible!
the issue is that no matter what i try i cant get the player attrivute can use magic to be true on the client and server when i use thr promity promt it jus prints out magicUnlockedevent false - What solutions have you tried so far? Did you look for solutions on the Developer Hub?
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local MagicPart = game.Workspace:WaitForChild(“MagicPart”)
local ProximityPrompt = MagicPart:WaitForChild(“MagicUnlocked”)
– Ensure MagicUnlockEvent exists
if not ReplicatedStorage:FindFirstChild(“MagicUnlockEvent”) then
local MagicUnlockEvent = Instance.new(“RemoteEvent”)
MagicUnlockEvent.Name = “MagicUnlockEvent”
MagicUnlockEvent.Parent = ReplicatedStorage
end
local MagicUnlockEvent = ReplicatedStorage:WaitForChild(“MagicUnlockEvent”)
– Proximity Prompt Trigger Logic
ProximityPrompt.Triggered:Connect(function(player)
– Check if the player already has magic unlocked
if not player:GetAttribute(“CanUseMagic”) then
– Initialize magic attributes
player:SetAttribute(“CanUseMagic”, true)
player:SetAttribute(“Mana”, 100) – Initial mana
player:SetAttribute(“MaxMana”, 100) – Initial max mana
-- Fire the event to unlock magic (send true)
MagicUnlockEvent:FireClient(player, true)
print(player.Name .. " has unlocked magic!")
else
-- If the player already has magic, fire the event with false
MagicUnlockEvent:FireClient(player, false)
print(player.Name .. " already has magic unlocked.")
end
end)
local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local TweenService = game:GetService(“TweenService”)
local player = Players.LocalPlayer
local MagicUnlockEvent = ReplicatedStorage:WaitForChild(“MagicUnlockEvent”) – Event to unlock magic
local ManaUpdatedEvent = ReplicatedStorage:WaitForChild(“UpdateManaGUI”) – Event for mana updates
– GUI elements for mana bar
local statBar = player:WaitForChild(“PlayerGui”):WaitForChild(“StatBar”)
local manaBar = statBar:WaitForChild(“Background”):WaitForChild(“ManaBar”)
local fill = manaBar:WaitForChild(“Fill”)
local label = manaBar:WaitForChild(“Label”)
– Tween settings for smooth GUI updates
local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
– Function to update the Mana GUI
local function updateManaGUI(currentMana, maxMana)
if not currentMana or not maxMana then
warn(“updateManaGUI: Invalid mana values received.”)
return
end
local manaPercentage = math.clamp(currentMana / maxMana, 0, 1)
local goal = UDim2.fromScale(manaPercentage, 1)
local tween = TweenService:Create(fill, tweenInfo, {Size = goal})
tween:Play()
label.Text = string.format("%d / %d", currentMana, maxMana)
print(string.format("Mana GUI updated: %d / %d", currentMana, maxMana))
end
– Function to toggle mana bar visibility
local function toggleManaBarVisibility(visible)
if manaBar then
manaBar.Visible = visible
print(“Mana bar visibility set to:”, visible)
else
warn(“toggleManaBarVisibility: Mana bar not found!”)
end
end
– Listen for the MagicUnlockEvent
MagicUnlockEvent.OnClientEvent:Connect(function(_, unlockMagic)
– Check if the player has magic unlocked
if unlockMagic then
print(“Magic unlocked! Showing mana bar.”)
toggleManaBarVisibility(true)
-- Initialize the mana bar with the player's current attributes
local currentMana = player:GetAttribute("Mana") or 0
local maxMana = player:GetAttribute("MaxMana") or 100
updateManaGUI(currentMana, maxMana)
else
-- If magic is not unlocked, hide the mana bar
print("MagicUnlockEvent received, but unlockMagic was false.")
toggleManaBarVisibility(false)
end
end)
– Initialize the mana bar visibility when the player joins the game
if player:GetAttribute(“CanUseMagic”) then
print(“Player already has magic. Showing mana bar.”)
toggleManaBarVisibility(true)
-- Update the mana GUI with the player's existing attributes
local currentMana = player:GetAttribute("Mana") or 0
local maxMana = player:GetAttribute("MaxMana") or 100
updateManaGUI(currentMana, maxMana)
else
print(“Player does not have magic yet. Hiding mana bar.”)
toggleManaBarVisibility(false)
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.