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

math.random rune curse script won't work? No error outputs

Asked by 3 years ago

I have a runebutton that when touched it finds if the object that touched it was a player and if so then start a cooldown and fire a RemoteEvent in ReplicatedStorage player and object

--local script
script.Parent.Touched:Connect(function(object)
    local touch = false
    if object.Parent:FindFirstChild("Humanoid") then
        local player = game.Players[object.Parent.Name]
        if touch == true then
            repeat
                wait(60)
            until touch == false
            game.ReplicatedStorage.RuneCurse:FireServer(player, object)
            touch = true
        end
    end
end)

This is a script in ServerScriptService and when that remoteevent is fired, check if the player has more than 250 of the currency and if so, take away 250 and do math.random. There is a 50/50 chance the player is cursed and lucky. If the number is 1 then kill the player and fire Broadcast to all clients. If the number is 2 then give the player 500 of the currency and fire to all clients Broadcast

--script
function cursefunction(player, object)
    if player:WaitForChild("leaderstats").Quacks.Value >= 250 then
    player:WaitForChild("leaderstats").Quacks.Value = player:WaitForChild("leaderstats").Quacks.Value - 250
    local curse = math.random(1, 2)
    if curse == 1 then
        object.Health = 0
        local cursechatsend
        game.ReplicatedStorage.Broadcast:FireAllClients(cursechatsend)
    elseif curse == 2 then
        player:WaitForChild("leaderstats").Quacks.Value = player:WaitForChild("leaderstats").Quacks.Value + 500
        local luckychatsend
        game.ReplicatedStorage.Broadcast:FireAllClients(luckychatsend)
    end
    end
end

game.ReplicatedStorage.RuneCurse.OnServerEvent:Connect(cursefunction)

This is a localscript in the remotevent Broadcast. If the player was lucky then send a message in chat as follows, otherwise send a different message.

--localscript
function broadcast(luckychatsend, player)
        local luckychat = game.StarterGui:SetCore("ChatMakeSystemMessage", {Text = player.."won 500 Quacks for the curse rune!";
        Font = Enum.Font.SourceSansBold;
        Color = Color3.fromRGB(0,255,255);
        FontSize = Enum.FontSize.Size18;
        })
end
game.ReplicatedStorage.Broadcast.OnServerEvent:Connect(broadcast)

function broadcastl(cursechatsend, player)
        local cursechat = game.StarterGui:SetCore("ChatMakeSystemMessage", {Text = player.."has died from the rune curse!";
        Font = Enum.Font.SourceSansBold;
        Color = Color3.fromRGB(255,0,0);
        FontSize = Enum.FontSize.Size18;
        })
end
game.ReplicatedStorage.Broadcast.OnServerEvent:Connect(broadcastl)

The scripts aren't working and there are no errors recorded. I tried printing messages but nothing showed up. What's going wrong?

1 answer

Log in to vote
0
Answered by 3 years ago

I think it's from your local script. I assume you use local touch to indicate when the part is touched. You put touch = true at the very end of the if then repeat until loop.

--local script
script.Parent.Touched:Connect(function(object)
    local touch = false
    if object.Parent:FindFirstChild("Humanoid") then
    touch = true
        local player = game.Players.LocalPlayer.Name
        if touch == true then
            repeat
                wait(1)
            until touch == false
            game.ReplicatedStorage.RuneCurse:FireServer(player, object)
    else
    touch = false
    return
        end
    end
end)

I'm not so sure but I think this should work.

0
I use touch as a cooldown so the player doesn't constantly touch it nekosiwifi 398 — 3y
0
Unfortunately, this doesn't work nekosiwifi 398 — 3y
Ad

Answer this question