What do you want to achieve? Keep it simple and clear!
i wanted when player clicks a button, it will change some Guis.
What is the issue? Include screenshots / videos if possible!
it didn’t change the Gui when i pressed the button.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
yes, but no results found.
Additional information
here is the code, both are localscript:
the button:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
ReplicatedStorage.WeaponDescriptionEvent.Sword:Fire()
end)
the Gui that i wanna change:
local name = script.Parent.SwordName
local desc = script.Parent.SwordDesc
local image = script.Parent.ImageLabel
local replicatedstorage = game:GetService("ReplicatedStorage")
local sword = replicatedstorage.WeaponDescriptionEvent.Sword
--rbxasset://textures/ui/GuiImagePlaceholder.png
local function onsword()
name.Text = "Sword"
desc.Text = "Just A Regular Sword, Nothing Special About Em'"
image.Image = "rbxassetid://15682244886"
end
You fired a RemoteEvent on the LocalScript. Now if you want to get the signal to the Script, the Script first has to receive it, so you have to add to your script the part that yoshi wrote here already.
– Create a LocalScript
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local tool = Instance.new(“Tool”)
tool.RequiresHandle = true
tool.Name = “Sword”
tool.RequiresHandle = true
tool.Parent = player.Backpack
– Create a ClickDetector
local clickDetector = Instance.new(“ClickDetector”)
clickDetector.Parent = tool
– Create a function to handle the sword activation
local function onActivated()
print(“Sword activated!”)
-- Add your sword functionality here, such as dealing damage to opponents
end
– Connect the function to the ClickDetector’s MouseClick event
clickDetector.MouseClick:Connect(onActivated)
– Create a LocalScript
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local tool = Instance.new(“Tool”)
tool.RequiresHandle = true
tool.Name = “Sword”
tool.RequiresHandle = true
tool.Parent = player.Backpack
– Create a ClickDetector
local clickDetector = Instance.new(“ClickDetector”)
clickDetector.Parent = tool
– Create a function to handle the sword activation
local function onActivated()
print(“Sword activated!”)
-- Add your sword functionality here, such as dealing damage to opponents
end
– Connect the function to the ClickDetector’s MouseClick event
clickDetector.MouseClick:Connect(onActivated)
– Create a LocalScript
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local tool = Instance.new(“Tool”)
tool.RequiresHandle = true
tool.Name = “Sword”
tool.RequiresHandle = true
tool.Parent = player.Backpack
– Create a ClickDetector
local clickDetector = Instance.new(“ClickDetector”)
clickDetector.Parent = tool
– Set cooldown time in seconds
local cooldownTime = 2
local canAttack = true
– Create a function to handle the sword activation
local function onActivated()
if canAttack then
canAttack = false
print(“Sword activated!”)
-- Add your sword functionality here, such as dealing damage to opponents
-- Reset the cooldown after a certain time
wait(cooldownTime)
canAttack = true
end
end
– Connect the function to the ClickDetector’s MouseClick event
clickDetector.MouseClick:Connect(onActivated)
“Add your sword functionality here, such as dealing damage to opponents”, it’s still about just changing some ui elements. I have the feeling that you use AI to help the OP, which is not bad, but this doesn’t really help out. And also because you type like godspeed to write the scripts
If the LocalScript is placed under workspace it will not run
If script.Parent is a ClickDetector, you have to use script.Parent.MouseClick
And in general BindableEvents suck and are the most useless way of script communication. So what you can do is combine the two of your script into one Local Script that you want to do:
-- IT DEPENDS ON WHAT BUTTON THIS IS!!!! I am assuming that its a ui button
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local button = --path to button, use waitforchild('s) if something errors
local swordname = script.Parent.SwordName
local sworddesc = script.Parent.SwordDesc
local swordimage = script.Parent.ImageLabel
local replicatedstorage = game:GetService("ReplicatedStorage")
local sword = replicatedstorage.WeaponDescriptionEvent.Sword
--rbxasset://textures/ui/GuiImagePlaceholder.png
local function onsword()
swordname.Text = "Sword"
sworddesc.Text = "Just A Regular Sword, Nothing Special About Em'"
swordimage.Image = "rbxassetid://15682244886"
end
button.MouseButton1Click:Connect(onsword)