Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to Convert this script to Be GUI Compatible?

Asked by 4 years ago
Edited 4 years ago

I figured out how to do it on when you click the screen, but since people keep doing it on accident, how would i make it so that it does it when you press a Button Gui? (sorry if im confusing)

game:GetService("ReplicatedStorage").Roka.OnServerEvent:Connect(function(player)
    local char = player.Character
    if not char:FindFirstChild"Rokakaka Fruit" then
    return
    end
    local human = char["Humanoid"]
    local location = player.Character.HumanoidRootPart.CFrame
    player:LoadCharacter()
    human.WalkSpeed = 16
    human.JumpPower = 50
    player.Character.HumanoidRootPart.CFrame = location
    if player.Data.Stand.Value > 1 then
        player.Data.Stand.Value = 1
    end
end)

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

The code you provide above is not the code responsible for actually enabling the click-on-screen function. However, I don't necessarily require it. Ensure this program below is a LocalScript, and is under the GUIButton.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("Roka")

local Button = script.Parent

Button.MouseButton1Click:Connect(function()
    RemoteEvent:FireServer()
end)

Your code also contains a lot of poor syntax practices, so I took the liberty of providing you with a cleaner program if you wish to use it:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("Roka")

local function OnEvent(Player)
    if (Player and Player.Character) then
        local Character = Player.Character
        if (Character:FindFirstChild("Rokakaka Fruit")) then
            local Humanoid = Character:WaitForChild("Humanoid")
            local Location = Humanoid.RootPart.Position
            Player:LoadCharacter()
            Humanoid.WalKSpeed = 16
            Humanoid.JumpPower = 50
            Character:MoveTo(Location)
            if (Player.Data.Sand.Value >1) then
                Player.Data.Sand.Value = 1
            end
        end
    end 
end
0
Thanks! this really helped! BrandonXYZ9 18 — 4y
0
Quick question, where does the last script go? local or server? and where do i put it sorry if this sounds dumb BrandonXYZ9 18 — 4y
0
Nvm figured it out, Thanks! BrandonXYZ9 18 — 4y
Ad

Answer this question