I’m new to scripting so please help. I was able to script on a part, but I don’t know how to transfer it to a button. Here is my script:
script.Parent.ClickDetector.MouseClick:Connect(function(player)
local explosion = Instance.new(“Explosion”)
explosion.BlastRadius = 50
explosion.BlastPressure = 500000
explosion.Position = player.Character.HumanoidRootPart.Position
explosion.Parent = player.Character.HumanoidRootPart
end)
1 Like
Make a Text Button and Text Button has an Event which fires when clicked
GuiButton.MouseButton1Click (roblox.com) .
1 Like
How would I write this out? Where would I put the MouseButton1Click?
This?
script.Parent.MouseButton1Click:Connect(function(player)
local explosion = Instance.new(“Explosion”)
explosion.BlastRadius = 50
explosion.BlastPressure = 500000
explosion.Position = player.Character.HumanoidRootPart.Position
explosion.Parent = player.Character.HumanoidRootPart
end)
IuaNerd
(IuaNerd)
July 17, 2021, 2:15pm
#4
Hey!
Note if you’re trying to do this with a button, it’s not going to be visible for all players, just you, unless you use a RemoteEvent | Roblox Creator Documentation to fire the server and execute your code there.
Now, first of all, to detect if your button is beeing pressed use the GuiButton | Roblox Creator Documentation event. This can be executed like this:
Button.MouseButton1Click:Connect(function()
-- Code here
end)
Now, as said, it wouldn’t be visible for all players, you would need a RemoteEvent | Roblox Creator Documentation .
First of all, create a Instance | Roblox Creator Documentation of it, for example in ReplicatedStorage | Roblox Creator Documentation .
Now reference it in the LocalScript | Roblox Creator Documentation of the button and in the Script | Roblox Creator Documentation of the server.
In the client script, add a RemoteEvent | Roblox Creator Documentation function and execute it.
This looks like this, for example:
RemoteEvent:FireServer()
After that, add a RemoteEvent | Roblox Creator Documentation event in the Script | Roblox Creator Documentation of the server.
This can be done like this:
RemoteEvent.OnServerEvent:Connect(function(player)
-- Code here
end)
In the Script | Roblox Creator Documentation of the server just add your own function and you should be fine!
I hope this could help you out with your problem!
Cheers
1 Like