so i made a gui, and a model inside the relicatestorage, i want to make that everytime i press the gui button, it will make the model clone and teleport the player to the part i placed inside a model and i want to make that the model inside the replicatestorage will spawn far from spawn, so what i tried is
i place this inside the startergui and it’s a serverscript:
local num = 0
game.ReplicatedStorage.EnterBattle.Gaster.OnServerEvent:Connect(function(plr)
num = num + 1
local map = game.ReplicatedStorage.BattleAreas.GasterArea:Clone()
local zed = num*100
local Teleport = "Teleporthere"
local teleportpart = map.Teleporthere
local button = script.Parent.Main.Battles.Gaster
map:SetPrimaryPartCFrame(CFrame.new(1000,1000,zed))
wait(1)
local player = plr
local debounce = false
local function helpme()
if not debounce then
debounce = true
local LowerTorso = player.Character.LowerTorso
LowerTorso.CFrame = teleportpart
end
end
button.Activated:connect(helpme)
while true do wait()
debounce = false
wait(7.5)
end
end)
also i tried to make sure that the model won’t spawn inside another model so i made the num thing
i also placed a monster inside the model , and i want to make that if you kill the monster it will give you Exp/Gold
hope it was understandable , thanks in advance
EDIT: i notice that i forgot to set model.Parent to Workspace , so it will actually show up in the map, but it’s still doesn’t teleports me
it’s still doesn’t works, is it suppose to be inside local script or server script, and i placed the script inside startergui, is it suppose to be in serverscriptsevice?
Can you send a screenshot of how your game is structured so I can understand your code a bit better?
EDIT: A TextButton has no Activated Connection if I remember correctly, so you should replace that with MouseButton1Click. (But only if it is a TextButton
edit: I’m not sure if that’s exactly the problem, it may not be. Let me know if it still doesn’t work. But this is a shorter / easier way to teleport players.
edit2: Your script should be in a ServerScript if it’s using OnServerEvent.
Server scripts aren’t meant to be placed in StarterGui. In general, if a script isn’t managing a Gui, you should avoid scripts in StarterGui in the first place.
What’s the purpose of the num variable? It looks like an arbitrary offset for the Z-axis for teleporting. I don’t think you particularly want that, because your character would be moving at odd heights.
This remote has no security. It can be spammed and abused easily or overwrite something that shouldn’t be happening (such as setting up multiple instances of the same event)
SetPrimaryPartCFrame tears apart your models slowly. I’d recommend placing the map where it should be in Studio and then all you’d need to do is parent it.
You’re defining functions inside OnServerEvent for whatever reason?
When teleporting a player, move them by their HumanoidRootPart, not their LowerTorso. You can also use that one Humanoid.Move(To) function or SetPrimaryPartCFrame but I don’t see much use in either of those.
Your coding conventions are jumbled. You should separate things out rather than force them all down into a function bound to OnServerEvent.
I’d rewrite it to be more clear and actually achieve what you need, such as structuring the code to be more event-based to avoid relying on strange and unreadable structures to get by.
Switch out the Activated with MouseButton1Click. I also suggest reading a bit more into RemoteEvents as they allow you proper replication. (And please don’t put a MouseButton1Click event in a Script, let a LocalScript handle that.)
Yeah, you don’t really need that at all. Take some time to think about the code and refurbish it: a good structure won’t require you to handle an edge case like that. For example, you can create a flag that determines if a battle has already been started to prevent do-overs like that.
I’m assuming that your game is singleplayer here. If there’s multiple players to a server, it’d be slightly more understandable but then that’s a separate problem to work around.