I’ve got this melee weapon. I want it to reduce the stamina bar inside of the Player’s PlayerGui, but I’m not sure how to reference the player and their PlayerGui inside of a normal script.
Get the player that’s using the Tool, then you can do something like Player.PlayerGui
You can use Remote events to achieve this.
I got this, but how would I use Character to find the Player?
local Tool = script.Parent
local Character = Tool.Parent
I believe it is,
local Character = tool.Parent
local plr = game.Players:GetPlayerFromCharacter(Character)
Never worked with tools, Could be wrong.
You can use the Character’s name and then do something like game.Players[Character.Name] too
It’s something like this:
local tool = script.Parent
local character = tool.Parent
local player = game:GetService("Players"):GetPlayerFromCharacter(character)
what does this error mean?
You cannot access PlayerGui in a server script, only way around this is using Remote Events or do this in a local script.
How would I use remote events to do this? I have no idea how to use them
Use this Remote Functions and Events
so, I should use server to client for this instance?
local players = game:GetService"Players"
local tool = script.Parent
tool.Equipped:Connect(function()
local character = tool.Parent
local player = players:GetPlayerFromCharacter(character)
if player then
local playerGui = player:FindFirstChildOfClass"PlayerGui"
if playerGui then
--Do code.
end
end
end)
tool.Unequipped:Connect(function()
local backpack = tool.Parent
local player = backpack.Parent
local playerGui = player:FindFirstChildOfClass"PlayerGui"
if playerGui then
--Do code.
end
end)
Server script inside the tool.