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

OnChatted Regen Script not working?

Asked by 9 years ago

Hi, I just created a script which only a certain person can regen a model/part by saying ":regen". When I tried it out, the script did not work. The script is not a LocalScript. It is a in a NormalScript.

-- onChatted regen script by PlayingOBC
Master = "PlayingOBC" -- Player who can use ":regen" command
model = game.Workspace.Regenerator -- Name of the model which needs to be regen.
backup = model:clone() 

function onChatted(msg, recipient, speaker) 

local source = string.lower(Master.Name) 
msg = string.lower(msg) 

if (msg == ":regen") then 
model:remove() 
model = backup:clone() 
model.Parent = game.Workspace 
model:makeJoints() 
end 

end 

function onPlayerEntered(newPlayer) 
Master.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, Master) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered) 

Please let me know what error I did. Thank you for reading/helping! :)

1 answer

Log in to vote
-1
Answered by 9 years ago

I have made some changes to your script and I have used a different event instead of childadded, I also included some validation as source was not being used. This script will now check against the players name. If you don't need it just remove the validation lines:-

local plrList = {"kingdom5", "Player", "PlayingOBC"} --List of accepted player

local model = game.Workspace.Regenerator --Model Location
local backup = model:clone() --Backup model, but you could just keep a copy in server storage

function regen(msg, plr) --regen function
    -- print("Plr:- " .. plr.Name .. " Said:- " .. msg ) --just for testing

    local found = false --stores if the player is found

    for i = 1, #plrList do -- loop through all player in the list
        if plrList[i] == plr.Name then found = true break end -- player is in the list so exit the loop to save time and set found to true
    end

    if found then -- player is found

        if string.lower(msg)  == ":regen" then -- msg comparison
            --action to take here           
            model:remove() 
            model = backup:clone() 
            model.Parent = game.Workspace 
            model:makeJoints() 
        end


    end 
end

game.Players.PlayerAdded:connect(function (plr)--new player joined
    plr.Chatted:connect(function (msg, rec) regen(msg, plr) end) --connects players to the regen function

end)

Hope this helps

0
Thank You for your help! :) PlayingOBC 70 — 9y
0
You don't actually help people with these answers, you just make them scripts that work. -rep Vlatkovski 320 — 9y
0
with comments of how it works, nice User#5423 17 — 9y
Ad

Answer this question