So... I am trying to explode everyone and send them a message but it is not working. Here is the code.
Serverside:
local gui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local pp = game:GetService("ProximityPromptService")
local phone = game:GetService("ReplicatedStorage")
local world = game.Workspace
local function pptrig (obj, ply)
for i,v in pairs(game.Players:GetChildren()) do
local player = world:FindFirstChild(v.Name)
local nuke = Instance.new("Explosion", world)
nuke.BlastRadius = 0.9
nuke.BlastPressure = 1000000
nuke.Position = player.HumanoidRootPart.Position
print("run")
phone.Exploded:FireClient(v, v.Name, ply.Name)
end
end
pp.PromptTriggered:Connect(pptrig)
Clientside:
local phone = game:GetService("ReplicatedStorage")
local gui = game:GetService("StarterGui")
gui:SetCore("test", {Text = "Ran"})
local function humiliation(me, ply)
gui:SetCore("test", {Text = "Ran"})
if ply ~= me then
gui:SetCore("Humiliation", {
Title = "Exploded!",
Text = "You have been exploded by "..ply..".",
Duration = 10,
})
elseif ply == me then
gui:SetCore("Humiliation", {
Title = "Exploded!",
Text = "You, "..me..", exploded yourself."
})
end
end
phone.Exploded.OnClientEvent:Connect(humiliation())
When I try to run it it gives me this:
StarterGui:SetCore must be called from a local script. (x2) - Studio
Players.GoldenRStar.PlayerGui.Script:19: attempt to concatenate nil with string - Server - Script:19
Exploded is a remote event and I wanted to Explode everyone and send them a message:
"You have been exploded by GuyThatPressesButtons." and
"You, GuyThatPressesButtons, exploded yourself."
this program tries to loop though every player, explodes them and sends them a fire from the remote event Exploded, then a client script catches it and processes it acordingly.
on the fire, it is sent the players name: v.Name and the player that pressed the button, on the client script both values are nil.
Related
I'm trying to make a gamepass script where when you join you will be told to buy a gamepass. but When you join the game the Gamepass promt wont show up. and the output does not give me a error
local marketplaceservice = game:GetService("MarketplaceService")
local gamepassid = 11585012233
local function PromtPurchase()
local players = game.Players.LocalPlayer
local haspass = false
local success, message = pcall(function()
local hasspass =
marketplaceservice:PromptGamePassPurchase(players.UserId,gamepassid)
if haspass == true then
print("Player has pass")
marketplaceservice:PromptGamePassPurchase(players, gamepassid)
else
marketplaceservice:PromptGamePassPurchase(players, gamepassid)
end
end)
wait(1)
promtPurchase()
local hasspass = marketplaceservice:PromptGamePassPurchase(players.UserId,gamepassid)
This is a prompting function, so it'll just prompt every time, you want to be using
local hasspass = marketplaceservice:UserOwnsGamePassAsync(players.UserId, gamepassid)
im trying to make a tag game that one player from the spectate team or nutural team will be chosen to be the tag and another will be chosen to be the runner. They'll both teleport to a small map, there the tag will have to try catch the runner before the times up.
Now my problem is that when the player loads to the game he does'nt autoassigned to the nuturalteam(spectateteam) and also when the players tp to the map they wont change the teams to a tager and runner they'll both be in the same team. Help will be appriciated!
Also i dont get any errors in the outpot besides "loadstring is not availble".
Here is the round system script:
Teams = game:GetService("Teams")
local SpectateTeam = game.Teams.Spectate
local ItTeam = game.Teams.It
local RunnerTeam = game.Teams.Runner
local roundlength = 5
local intermissionLength = 4
local inRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local LobbySpawn = workspace.Map.SpawnLobby
local MapSpawnIt = workspace.Map.SpawnMapIt
local MapSpawnRunner = workspace.Map.SpawnMapRunner
local frame = game.StarterGui.ScreenGuimenu.Frame
local KillerSpawn = workspace.Map.SpawnMapIt
local lobbyspace = workspace.Lobbyspace
game.Players.PlayerAdded:Connect(function(player)
player.Team = SpectateTeam
end)
inRound.Changed:Connect(function(player)
if inRound.Value == true then
local chosen = Players:GetChildren()[math.random(1, #Players:GetChildren())]
print(" is It")
chosen.Team = ItTeam
local runner = SpectateTeam:GetPlayers()[math.random(1, #Players:GetChildren())]
print(" is Runner")
runner.Team = Teams.Runner
wait()
runner.Character.HumanoidRootPart.CFrame = MapSpawnRunner.CFrame
chosen.Character.HumanoidRootPart.CFrame = KillerSpawn.CFrame
end
if inRound.Value == false then
for _, player in pairs(game.Players:GetChildren(player)) do
local char = player.Character
char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
player.Team = SpectateTeam
end
end
end)
local function RoundTimer()
while wait() do
for i = intermissionLength, 0, -1 do
inRound.Value = false
wait(1)
Status.Value = "Intermission:" .. i .."seconds left!"
end
for i = roundlength, 0, -1 do
inRound.Value = true
wait(1)
Status.Value = "Game:" .. i .."seconds left!"
end
end
end
spawn(RoundTimer) ```
I found the answer! i just forgot to sync the color of the teams with the spawns :)
So I'm trying to give the players different weapons based on what team they are on. I'm trying to do this via creating a instance string value and adding it to a folder which is the player's name in ReplicatedStorage, But it only gets updated on the Player's side, Not for the server. I'm trying to fix this via making a script in ReplicatedStorage and calling the function named handleTeams but I always get the error which says that handleTeams is not the child of the script.
LocalScript (LocalScript) (Players > Player1 > PlayerGui > InsertedObjects > team > Russia)
local p = script.Parent.Parent.Parent.Parent.Parent.Name
script.Parent.MouseButton1Click:Connect(function()
game.Players[p].TeamColor = BrickColor.new("Really blue")
game.Workspace[p].Humanoid.Health = 0
script.Parent.Parent.Parent.Enabled = false
local Player = Instance.new("Folder")
local GameTag = Instance.new("StringValue")
GameTag.Value = "USA"
GameTag.Name = "TeamName"
Player.Name = game.Players:FindFirstChild(p).Name
script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.ReplicatedStorage.Script(Player, GameTag)
end)
TeamGear (Script) (Workspace > TeamGear)
function onSpawned(plr)
if script.Parent.Parent.ReplicatedStorage.Teams[plr.Name].TeamName == "Russia" then
local tools = script.Parent.Parent.Teams.Russia:GetChildren()
for _,c in pairs(tools) do
c:Clone().Parent = plr.Backpack
end
end
if script.Parent.Parent.ReplicatedStorage.Teams[plr.Name].TeamName == "USA" then
local tools = script.Parent.Parent.Teams.USA:GetChildren()
for _,c in pairs(tools) do
c:Clone().Parent = plr.Backpack
end
end
end
Script (Script) (ReplicatedStorage > Script)
function handleTeams(player, tag)
player.Parent = script.Parent.Teams
tag.Parent = player
end
If you want to define a script in ReplicatedStorage that can be called from other scripts, it has to be a ModuleScript.
For example if you want to have a script in ReplicatedStorage that prints "Hello World", then you'd create a ModuleScript (not a Script) like this:
ReplicatedStorage > ModuleScript
local module = {}
function module.Hello()
print("Hello, World!")
end
return module
Then from a LocalScript or Script you can call it like so:
local HelloModule = require(game.ReplicatedStorage:WaitForChild("ModuleScript"))
HelloModule.Hello()
So I am using a remote function, as seen at the end, and for some reason, a normal assignment of a variable won't work, it is giving me the error message, "Unable to cast value to Object," what is wrong?
local storeEvent = script.Parent.Parent.OpenStore
local slotNum = 1
script.Parent.Touched:Connect(function (hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
storeEvent:InvokeClient(slotNum)
end
end)
and connecting to the other script:
script.Parent.OnInvoke:Connect(function (slot)
local StoreArrows = game.ReplicatedStorage.StoreArrows
StoreArrows.SlotNum.Value = slot
local cam = game.Workspace.Camera
local storeButtons = script.Parent
local camNum = game.ReplicatedStorage.StoreArrows.CamNum.Value
local camNumInst = game.Workspace.CamStorage:WaitForChild("Cam-"..camNum)
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = camNumInst.CFrame
local clonedStoreButtons = StoreArrows:Clone()
clonedStoreButtons.Parent = player.PlayerGui.ScreenGui
end)
Keep in mind that many clients connect to a server at a time. So when you call a RemoteEvent's InvokeClient function, you have to tell it which client to invoke it on. The first parameter to InvokeClient is supposed to be the player, that's why the error is telling you that it cannot cast the slotNum value to a player object.
local storeEvent = script.Parent.Parent.OpenStore
local slotNum = 1
script.Parent.Touched:Connect(function(hit)
-- check that the thing that we touched is actually a player
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
-- tell that player to open the store
storeEvent:InvokeClient(player, slotNum)
end
end)
this is my code at the moment:
local players = game:WaitForChild("Players")
local function createLeaderboard(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
local baseclicks = Instance.new("IntValue", stats)
baseclicks.Name = "baseclicks"
stats.Parent = player
baseclicks.Value = 100
end
players.PlayerAdded:connect(createLeaderboard)
Im not sure if i need a clickdetector with a script inside or??
i dont know, please help.
If you don't want ClickDetectors on the Baseplate, simply, you could use mouse.Target. For example:
-- serverscript
local players = game:GetService("Players");
local function createLeaderboard(player);
local stats = Instance.new("Folder", player);
stats.Name = "leaderstats";
local baseclicks = Instance.new('IntValue', stats);
baseclicks.Name = 'baseclicks'
baseclicks.Value = 100;
end
-- localscript in startercharacterscript
local players = game:GetService("Players");
local client = players.LocalPlayer;
local mouse = client:GetMouse(); --method for getting the client's mouse
local event = game.ReplicatedStorage.OnClick --our remote event
local leaderstats = client.leaderstats or client:WaitForChild("leaderstats");
local clickvalue = leaderstats.baseclicks or leaderstats:WaitForChild("baseclicks");
mouse.Button1Down:Connect(function()
if not (mouse.Target) then return; end
if (mouse.Target.Name == "Baseplate") then
event:FireServer(clickvalue.Value + 1); --fire the remote event
end
end
end)
-- server script in serverscriptservice for remote event receiver
game.ReplicatedStorage.OnClick.OnServerEvent:Connect(function(Player, Value)
Player.leaderstats.baseclicks.Value = Value;
end
However, when it comes to the game having multiple players clicking at once, remote events are not recommended as they are more than likely going to lag the server or cause network traffic - you're better off using ClickDetectors.